'Include' HTML file in ASPX page
-
I'm sure the answer to this is really simple. But any help would be appreciated as it's driving me up the wall. I have an aspx page, with a button. When I click the button I want it to display HTML generated from another ASPX page, a bit like an include. So, I've turned the page I want to include into a Web User Control. When the user clicks the button, I call a method on the User Control to generate the HTML (using response.write lines). Problem: The HTML appears at the TOP of the calling page, and moves all the other controls down. How do I make the HTML appear where I want it to? (I've tried putting it into a frame, and a table, but it still appears at the top of the page. Example code follows (project name is 'menu', code is VB.NET):
**LetterPrint.aspx (My main page)** <%@ Page Language="vb" AutoEventWireup="false" Codebehind="LetterPrint.aspx.vb" Inherits="menu.LetterPrint"%> <%@ Register TagPrefix="uc1" TagName="ParseMessage" Src="ParseMessage.ascx" %> <HTML> <HEAD> <title>LetterPrint</title> </HEAD> <body> <form id="Form1" method="post" runat="server"> <asp:Button id="cmdShow" runat="server" Text="Show Letters"></asp:Button> <br> <br> <uc1:ParseMessage id="ParseMessage1" runat="server" visible="false"></uc1:ParseMessage> </form> </body> </HTML> **LetterPrint.aspx.vb** Public Class LetterPrint Inherits System.Web.UI.Page Protected WithEvents cmdShow As System.Web.UI.WebControls.Button Protected WithEvents ParseMessage1 As menu.ParseMessage Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click ParseMessage1.ShowLetters() End Sub End Class ------------------------------------------------------------------------------------- **ParseMessage.ascx (My Web User Control)** <%@ Control Language="vb" AutoEventWireup="false" Codebehind="ParseMessage.ascx.vb" Inherits="menu.ParseMessage" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> **ParseMessage.ascx.vb** Public MustInherit Class ParseMessage Inherits System.Web.UI.UserControl Public Sub ShowLetters() Response.Write("<b> This is the HTML I want to include <br>") Response.Write("<i> But it appears at the TOP of the page </i> <br>") Response.Write("<b> Instead of underneath the button <
-
I'm sure the answer to this is really simple. But any help would be appreciated as it's driving me up the wall. I have an aspx page, with a button. When I click the button I want it to display HTML generated from another ASPX page, a bit like an include. So, I've turned the page I want to include into a Web User Control. When the user clicks the button, I call a method on the User Control to generate the HTML (using response.write lines). Problem: The HTML appears at the TOP of the calling page, and moves all the other controls down. How do I make the HTML appear where I want it to? (I've tried putting it into a frame, and a table, but it still appears at the top of the page. Example code follows (project name is 'menu', code is VB.NET):
**LetterPrint.aspx (My main page)** <%@ Page Language="vb" AutoEventWireup="false" Codebehind="LetterPrint.aspx.vb" Inherits="menu.LetterPrint"%> <%@ Register TagPrefix="uc1" TagName="ParseMessage" Src="ParseMessage.ascx" %> <HTML> <HEAD> <title>LetterPrint</title> </HEAD> <body> <form id="Form1" method="post" runat="server"> <asp:Button id="cmdShow" runat="server" Text="Show Letters"></asp:Button> <br> <br> <uc1:ParseMessage id="ParseMessage1" runat="server" visible="false"></uc1:ParseMessage> </form> </body> </HTML> **LetterPrint.aspx.vb** Public Class LetterPrint Inherits System.Web.UI.Page Protected WithEvents cmdShow As System.Web.UI.WebControls.Button Protected WithEvents ParseMessage1 As menu.ParseMessage Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click ParseMessage1.ShowLetters() End Sub End Class ------------------------------------------------------------------------------------- **ParseMessage.ascx (My Web User Control)** <%@ Control Language="vb" AutoEventWireup="false" Codebehind="ParseMessage.ascx.vb" Inherits="menu.ParseMessage" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> **ParseMessage.ascx.vb** Public MustInherit Class ParseMessage Inherits System.Web.UI.UserControl Public Sub ShowLetters() Response.Write("<b> This is the HTML I want to include <br>") Response.Write("<i> But it appears at the TOP of the page </i> <br>") Response.Write("<b> Instead of underneath the button <
You are using Grid Layout in either the page or the user control. stop. use flow layout.
-
You are using Grid Layout in either the page or the user control. stop. use flow layout.
I'm using flow layout in both - The first thing I do when I create a new web form is set the layout to flowlayout! :)
-
I'm using flow layout in both - The first thing I do when I create a new web form is set the layout to flowlayout! :)
wait, i just saw the "using Response.Write" bit. don't do that. just put controls in your UserControl, and set the Visible property. using Response.Write is not recommended in asp.net, and is only around in the same place for backwards compatibility. use the page rendering framework as it is intended.
-
wait, i just saw the "using Response.Write" bit. don't do that. just put controls in your UserControl, and set the Visible property. using Response.Write is not recommended in asp.net, and is only around in the same place for backwards compatibility. use the page rendering framework as it is intended.
The real purpose of my usercontrol is to transform an XML file I give it, and supply the output in HTML. I just used these three response.write lines to keep the example short. I'll have a look at it again - I think there's some kind of XML web control I might be able to use. Thanks, John.
-
The real purpose of my usercontrol is to transform an XML file I give it, and supply the output in HTML. I just used these three response.write lines to keep the example short. I'll have a look at it again - I think there's some kind of XML web control I might be able to use. Thanks, John.
yes, System.Web.UI.WebControls.Xml
-
yes, System.Web.UI.WebControls.Xml
Actually, I've discovered the proper .NET way of doing something like this. You are correct, response.write is bad in ASP.NET. So what I did was override the Render() method of System.Web.UI.UserControl in my usercontrol. This works great! (I'm finally starting to understand the benefits of .NET) So, I've done this in the usercontrol: Public MustInherit Class ParseMessage Inherits System.Web.UI.UserControl Private myOutput As String Protected Overrides Sub Render(ByVal wrt As HtmlTextWriter) wrt.Write(myOutput) wrt.Write("Hello there!
I'm a usercontrolokay?") End Sub Public Sub mytest() myOutput = " some new output html! " End Sub End Class Which does exactly what I want. John.
-
I'm sure the answer to this is really simple. But any help would be appreciated as it's driving me up the wall. I have an aspx page, with a button. When I click the button I want it to display HTML generated from another ASPX page, a bit like an include. So, I've turned the page I want to include into a Web User Control. When the user clicks the button, I call a method on the User Control to generate the HTML (using response.write lines). Problem: The HTML appears at the TOP of the calling page, and moves all the other controls down. How do I make the HTML appear where I want it to? (I've tried putting it into a frame, and a table, but it still appears at the top of the page. Example code follows (project name is 'menu', code is VB.NET):
**LetterPrint.aspx (My main page)** <%@ Page Language="vb" AutoEventWireup="false" Codebehind="LetterPrint.aspx.vb" Inherits="menu.LetterPrint"%> <%@ Register TagPrefix="uc1" TagName="ParseMessage" Src="ParseMessage.ascx" %> <HTML> <HEAD> <title>LetterPrint</title> </HEAD> <body> <form id="Form1" method="post" runat="server"> <asp:Button id="cmdShow" runat="server" Text="Show Letters"></asp:Button> <br> <br> <uc1:ParseMessage id="ParseMessage1" runat="server" visible="false"></uc1:ParseMessage> </form> </body> </HTML> **LetterPrint.aspx.vb** Public Class LetterPrint Inherits System.Web.UI.Page Protected WithEvents cmdShow As System.Web.UI.WebControls.Button Protected WithEvents ParseMessage1 As menu.ParseMessage Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click ParseMessage1.ShowLetters() End Sub End Class ------------------------------------------------------------------------------------- **ParseMessage.ascx (My Web User Control)** <%@ Control Language="vb" AutoEventWireup="false" Codebehind="ParseMessage.ascx.vb" Inherits="menu.ParseMessage" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> **ParseMessage.ascx.vb** Public MustInherit Class ParseMessage Inherits System.Web.UI.UserControl Public Sub ShowLetters() Response.Write("<b> This is the HTML I want to include <br>") Response.Write("<i> But it appears at the TOP of the page </i> <br>") Response.Write("<b> Instead of underneath the button <
try this link is very interesting about your problem. http://www.codeguru.com/net\_asp/ScriptGen.html Bye. --- for free ---