Header/Footer by Inheritance?
-
What is my question? Hmm... Is there a clever .Net way to achieve what we used to do with includes with regard to headers and footers? In ASP you might do something like this .... <%Option Explicit%> <% Response.Write "HelloWorld" %> This is all fine and dandy, unless you want to actually do something dynamic in your header or footer (not out of the question) and pass through variables and such. For example, I often draw the side naviagtion in the header include and pass through the security level of the user (which alters the available menu options) so I usually do it like so... <%Option Explicit%> <% DrawHeader iLoginSecurityLevel Response.Write "HelloWorld" DrawFooter iLoginSecurityLevel %> Ok, so now the guts of my question with that in mind would be, is there a nice way to do this via perhaps the code-behind architecture and inheritance in ASP.Net? I am thinking that perhaps you'd have your own page which would inherit from Page and would implement a method to draw the header and footer on every page. If so, at what stage would I be writing the header and footer? Is there Page events that I could respond to before and after the .aspx stuff is written? Just wondering if anyone has taken this approach really and whether it worked out well. Ta in advance JBoy Talk is cheap because supply exceeds demand
-
What is my question? Hmm... Is there a clever .Net way to achieve what we used to do with includes with regard to headers and footers? In ASP you might do something like this .... <%Option Explicit%> <% Response.Write "HelloWorld" %> This is all fine and dandy, unless you want to actually do something dynamic in your header or footer (not out of the question) and pass through variables and such. For example, I often draw the side naviagtion in the header include and pass through the security level of the user (which alters the available menu options) so I usually do it like so... <%Option Explicit%> <% DrawHeader iLoginSecurityLevel Response.Write "HelloWorld" DrawFooter iLoginSecurityLevel %> Ok, so now the guts of my question with that in mind would be, is there a nice way to do this via perhaps the code-behind architecture and inheritance in ASP.Net? I am thinking that perhaps you'd have your own page which would inherit from Page and would implement a method to draw the header and footer on every page. If so, at what stage would I be writing the header and footer? Is there Page events that I could respond to before and after the .aspx stuff is written? Just wondering if anyone has taken this approach really and whether it worked out well. Ta in advance JBoy Talk is cheap because supply exceeds demand
You can actually still use the #Include if you would like even with
.aspx
pages, however to answer you question there is a .NET way of handling this. This is through the process of what Microsoft calls User Controls (file type.ascx
). I have included a link below to a MSDN page that shows how to convert from the older style to the new user controls. I hope this answers your question. Converting a Web Forms Page to a User Control [New Window] Nick Parker -
You can actually still use the #Include if you would like even with
.aspx
pages, however to answer you question there is a .NET way of handling this. This is through the process of what Microsoft calls User Controls (file type.ascx
). I have included a link below to a MSDN page that shows how to convert from the older style to the new user controls. I hope this answers your question. Converting a Web Forms Page to a User Control [New Window] Nick Parker -
User controls ignore and
tags, so it would not be possible to have a Header user control that defines say the following ... Northwind
JBoy :confused:
True, I guess that's why they still allow the #include. :) Nick Parker