Search code examples
c#asp.netincludeworkflowresponse.write

ASP.NET Pageflow Info


So I'm trying to use C# to grab stored HTML in a database and then display it between a set HTML header and footer (I have a couple of these for different pages, so a masterpage would make life more complicated rather than less. I also come from a PHP background where this is sort of the way things work).

<!--#include virtual="header.html" --> 
<% @Page Language="C#" Debug="true" %>
<% @Import Namespace="System.Data.Odbc" %>
<% @Import Namespace="System.Web.Configuration" %>

<script language="C#" runat="server">
void Page_Load(object sender,EventArgs e) {
           //Gets the HTML Successfully
           //Response.Write(fetched_html);
    }
</script>
<!--#include virtual="footer.html" --> 

Unfortunately with the current workflow the code generates content before the header or footer are put on the page, putting all the stored HTML at the top of the page before the header. I've tried a couple different Page_Events and none of them seem to work, so I need to know what to do.

Is there an equally simple way to reference and insert a simple html header file that would render before any of the Page_Events? I've tried Page_PreLoad and others to no success. Either the code is not fetched at all or I run into the same issue.


Solution

  • Use a MasterPage with a ContentPlaceholder. Then, on the content page, use a Literal and put the HTML in there.

    See "The difference between literal and label".