I am trying to dynamically "insert" a header.ascx file into all of my .aspx files. My header.ascx looks something like this:
I then have a Page.cs file which is a base class I created using instructions I found on the web:
Finally, my test.aspx page has the following code:
Logically, this should work the way it is written. Unfortunately, I am new to ASP.NET so I don't know what I'm doing wrong. I get the error "Unexpected end of file looking for </form> tag" in header.ascx. What seems to be happening is that it is trying to compile header.ascx before including it in my test.aspx. Since test.aspx has the closing tags for form, body, and HTML, it is not working.
Does anyone know what I can do to make this work? Eventually, I will have a footer file that will have all of the closing tags.. I assume that I can insert this into all of the pages by adding the following line to my Page class:
I am not sure if the integer 1 works there or if I need to do it another way. Please put forth your thoughts and comments. Thank you.
Varol
Code:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="header.ascx.cs" Inherits="myNamespace.header" TargetSchema="[URL unfurl="true"]http://schemas.microsoft.com/intellisense/ie5"[/URL] %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>My Title</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="[URL unfurl="true"]http://schemas.microsoft.com/intellisense/ie5">[/URL]
<link id="cssLink" runat="server"></link>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
I then have a Page.cs file which is a base class I created using instructions I found on the web:
Code:
using System;
using System.Web.UI;
namespace myNamespace
{
public class Page : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Controls.AddAt(0, LoadControl("header.ascx"));
}
}
}
Finally, my test.aspx page has the following code:
Code:
<%@ Page language="c#" Inherits="myNamespace.Page" %>
..... some HTML here .......
</form>
</body>
</HTML>
Logically, this should work the way it is written. Unfortunately, I am new to ASP.NET so I don't know what I'm doing wrong. I get the error "Unexpected end of file looking for </form> tag" in header.ascx. What seems to be happening is that it is trying to compile header.ascx before including it in my test.aspx. Since test.aspx has the closing tags for form, body, and HTML, it is not working.
Does anyone know what I can do to make this work? Eventually, I will have a footer file that will have all of the closing tags.. I assume that I can insert this into all of the pages by adding the following line to my Page class:
Code:
Controls.AddAt(1, LoadControl("footer.ascx"));
I am not sure if the integer 1 works there or if I need to do it another way. Please put forth your thoughts and comments. Thank you.
Varol