Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. 'Include' HTML file in ASPX page

'Include' HTML file in ASPX page

Scheduled Pinned Locked Moved ASP.NET
helpquestioncsharphtml
8 Posts 3 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Honan
    wrote on last edited by
    #1

    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 <

    A E 2 Replies Last reply
    0
    • J John Honan

      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 <

      A Offline
      A Offline
      Andy Smith
      wrote on last edited by
      #2

      You are using Grid Layout in either the page or the user control. stop. use flow layout.

      J 1 Reply Last reply
      0
      • A Andy Smith

        You are using Grid Layout in either the page or the user control. stop. use flow layout.

        J Offline
        J Offline
        John Honan
        wrote on last edited by
        #3

        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! :)

        A 1 Reply Last reply
        0
        • J John Honan

          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! :)

          A Offline
          A Offline
          Andy Smith
          wrote on last edited by
          #4

          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.

          J 1 Reply Last reply
          0
          • A Andy Smith

            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.

            J Offline
            J Offline
            John Honan
            wrote on last edited by
            #5

            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.

            A 1 Reply Last reply
            0
            • J John Honan

              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.

              A Offline
              A Offline
              Andy Smith
              wrote on last edited by
              #6

              yes, System.Web.UI.WebControls.Xml

              J 1 Reply Last reply
              0
              • A Andy Smith

                yes, System.Web.UI.WebControls.Xml

                J Offline
                J Offline
                John Honan
                wrote on last edited by
                #7

                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 usercontrol

                okay?") End Sub Public Sub mytest() myOutput = " some new output html! " End Sub End Class Which does exactly what I want. John.

                1 Reply Last reply
                0
                • J John Honan

                  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 <

                  E Offline
                  E Offline
                  Egidio
                  wrote on last edited by
                  #8

                  try this link is very interesting about your problem. http://www.codeguru.com/net\_asp/ScriptGen.html Bye. --- for free ---

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups