473,320 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Header/Footer Block Control Idea, but not Templated Control

I keep running into this over and over again...
I want a block server control that renders a header and footer, and child
controls in between.
But I don't want a templated control, for the following reasons:

1) Render blocks are not allowed inside a templated control.
2) I want the inner controls scoped at the parent aspx (or ascx), not at the
template naming container.

This type of control would be ideal for website headers and footers, or
something like a control that simulates a windows tab control with tabs at
the top with a table border around the contents.

For example, for headers and footers, I do this alot:

<%@ Page Inherits="DumbCalculatorPage" %>
<%@ Register TagPrefix="MyStuff" TagName="Header" Src="Header.ascx" %>
<%@ Register TagPrefix="MyStuff" TagName="Footer" Src="Footer.ascx" %>

<html>
<head>
<title>Stupid Dumb Calculator</title>
</head>
<body>
<form runat="server">
<MyStuff:Header runat="server" />
This is a page
Sum: <%= Total %>
<p>
Add This Many: <asp:TextBox id="MyTextBox" runat="server" />
<asp:Button OnClick="DoSomething" Text="Go" runat="server" />
<MyStuff:Footer runat="server" />
</form>
</body>
</html>

Code behind:

public class DumbCalculatorPage : Page {
public int Total {
get {
if(ViewState["Total"] == null) {
ViewState["Total"] = 0;
}
return((int) ViewState["Total"]);
}
set {
ViewState["Total"] = value;
}
}

protected void DoSomething(object sender, EventArgs e) {
Total += int.Parse(MyTextBox.Text);
}

protected TextBox MyTextBox;
}

Now, wouldn't it be great to be able to change that aspx page to this, and
still have it compile and work with the same code behind class:

<%@ Page Inherits="DumbCalculatorPage" %>
<%@ Register TagPrefix="MyStuff" TagName="HeaderFooter"
Src="HeaderFooter.astx" %>

<html>
<head>
<title>Stupid Dumb Calculator</title>
</head>
<body>
<form runat="server">
<MyStuff:HeaderFooter runat="server">
Sum: <%= Total %>
<p>
Add This : <asp:TextBox id="MyTextBox" runat="server" />
<asp:Button OnClick="DoSomething" Text="Go" runat="server" />
</MyStuff:HeaderFooter>
</form>
</body>
</html>

You'll noticed that I've invented a new extension: "astx" T for template (I
can't think of a better name, sorry).
What does an astx look like? very similar to ascx with a couple new tags:

<%@ TemplateControl ... %>

<table>
<tr>
<td>Header top</td>
</tr>
<tr>
<td>
<%@ ParentScope %>
</td>
</tr>
<tr>
<td>Footer row</td>
</tr>
</table>

How would this work? Well the TemplateControl would need two controls
collections, HeaderControls and FooterControls. And two Render methods
RenderHeader and RenderFooter. (The inner controls defined on the page
belong to the parent! It doesn't need to reference them.) During the
render phase of the page, the page would have to call RenderHeader, then
render the inner controls where the ParentScope tag is, then RenderFooter.

Now if you are talking about a static header and footer like my example, it
seems like alot of extra work to change the framework to support this. But
imagine a more complex control, like a tab control that has tabs and that is
rendered as a table around it's contents. Then add properties to the tab
control. Add a property of tab alignment: TabAlignment="Top" versus
TabAlignment="Bottom" or TabAlignment="Right". Then add data binding to the
tab control to determine what tabs to show, and events for clicking on the
tab links. Now the header and footer are very closely tied together, and do
some neat stuff. The idea of this kind of Template becomes much more
interesting.

Implementing this as a templated control we loose our render blocks and
scoping. Why should the page have to search the template control for it's
inner text box? Why can't I use that simple render block?
Implementing this as two separate controls, we loose the connection between
header and footer. It's tough to find out where our td/tr/table mismatches
are between header and footer in different controls. Properties for the
header and footer aren't tied together in any way if they affect the
rendering.

Have I gone insane? Or is this a good idea? Or is there a similar way to
do this already that I am overlooking that does what I want? Is there a
reason this wouldn't work? (Seems the control hierarchy would be a bit odd
:)

I just keep running into this and I want a better solution than the current
template control implementation.
Nov 18 '05 #1
3 1892
If your target browsers are uplevel, what about using absolute positioning
instead? Then you can just have everything in the header, including a div
called Footer which is positioned to be at the bottom of the page ...

Justin

"John Crowley" <ax*****@hotmail.com> wrote in message
news:av***********************@twister.southeast.r r.com...
I keep running into this over and over again...
I want a block server control that renders a header and footer, and child
controls in between.
But I don't want a templated control, for the following reasons:

1) Render blocks are not allowed inside a templated control.
2) I want the inner controls scoped at the parent aspx (or ascx), not at the template naming container.

This type of control would be ideal for website headers and footers, or
something like a control that simulates a windows tab control with tabs at
the top with a table border around the contents.

For example, for headers and footers, I do this alot:

<%@ Page Inherits="DumbCalculatorPage" %>
<%@ Register TagPrefix="MyStuff" TagName="Header" Src="Header.ascx" %>
<%@ Register TagPrefix="MyStuff" TagName="Footer" Src="Footer.ascx" %>

<html>
<head>
<title>Stupid Dumb Calculator</title>
</head>
<body>
<form runat="server">
<MyStuff:Header runat="server" />
This is a page
Sum: <%= Total %>
<p>
Add This Many: <asp:TextBox id="MyTextBox" runat="server" />
<asp:Button OnClick="DoSomething" Text="Go" runat="server" />
<MyStuff:Footer runat="server" />
</form>
</body>
</html>

Code behind:

public class DumbCalculatorPage : Page {
public int Total {
get {
if(ViewState["Total"] == null) {
ViewState["Total"] = 0;
}
return((int) ViewState["Total"]);
}
set {
ViewState["Total"] = value;
}
}

protected void DoSomething(object sender, EventArgs e) {
Total += int.Parse(MyTextBox.Text);
}

protected TextBox MyTextBox;
}

Now, wouldn't it be great to be able to change that aspx page to this, and
still have it compile and work with the same code behind class:

<%@ Page Inherits="DumbCalculatorPage" %>
<%@ Register TagPrefix="MyStuff" TagName="HeaderFooter"
Src="HeaderFooter.astx" %>

<html>
<head>
<title>Stupid Dumb Calculator</title>
</head>
<body>
<form runat="server">
<MyStuff:HeaderFooter runat="server">
Sum: <%= Total %>
<p>
Add This : <asp:TextBox id="MyTextBox" runat="server" />
<asp:Button OnClick="DoSomething" Text="Go" runat="server" />
</MyStuff:HeaderFooter>
</form>
</body>
</html>

You'll noticed that I've invented a new extension: "astx" T for template (I can't think of a better name, sorry).
What does an astx look like? very similar to ascx with a couple new tags:

<%@ TemplateControl ... %>

<table>
<tr>
<td>Header top</td>
</tr>
<tr>
<td>
<%@ ParentScope %>
</td>
</tr>
<tr>
<td>Footer row</td>
</tr>
</table>

How would this work? Well the TemplateControl would need two controls
collections, HeaderControls and FooterControls. And two Render methods
RenderHeader and RenderFooter. (The inner controls defined on the page
belong to the parent! It doesn't need to reference them.) During the
render phase of the page, the page would have to call RenderHeader, then
render the inner controls where the ParentScope tag is, then RenderFooter.

Now if you are talking about a static header and footer like my example, it seems like alot of extra work to change the framework to support this. But imagine a more complex control, like a tab control that has tabs and that is rendered as a table around it's contents. Then add properties to the tab
control. Add a property of tab alignment: TabAlignment="Top" versus
TabAlignment="Bottom" or TabAlignment="Right". Then add data binding to the tab control to determine what tabs to show, and events for clicking on the
tab links. Now the header and footer are very closely tied together, and do some neat stuff. The idea of this kind of Template becomes much more
interesting.

Implementing this as a templated control we loose our render blocks and
scoping. Why should the page have to search the template control for it's
inner text box? Why can't I use that simple render block?
Implementing this as two separate controls, we loose the connection between header and footer. It's tough to find out where our td/tr/table mismatches are between header and footer in different controls. Properties for the
header and footer aren't tied together in any way if they affect the
rendering.

Have I gone insane? Or is this a good idea? Or is there a similar way to
do this already that I am overlooking that does what I want? Is there a
reason this wouldn't work? (Seems the control hierarchy would be a bit odd :)

I just keep running into this and I want a better solution than the current template control implementation.

Nov 18 '05 #2
If your target browsers are uplevel, what about using absolute positioning
instead? Then you can just have everything in the header, including a div
called Footer which is positioned to be at the bottom of the page ...

Justin

"John Crowley" <ax*****@hotmail.com> wrote in message
news:av***********************@twister.southeast.r r.com...
I keep running into this over and over again...
I want a block server control that renders a header and footer, and child
controls in between.
But I don't want a templated control, for the following reasons:

1) Render blocks are not allowed inside a templated control.
2) I want the inner controls scoped at the parent aspx (or ascx), not at the template naming container.

This type of control would be ideal for website headers and footers, or
something like a control that simulates a windows tab control with tabs at
the top with a table border around the contents.

For example, for headers and footers, I do this alot:

<%@ Page Inherits="DumbCalculatorPage" %>
<%@ Register TagPrefix="MyStuff" TagName="Header" Src="Header.ascx" %>
<%@ Register TagPrefix="MyStuff" TagName="Footer" Src="Footer.ascx" %>

<html>
<head>
<title>Stupid Dumb Calculator</title>
</head>
<body>
<form runat="server">
<MyStuff:Header runat="server" />
This is a page
Sum: <%= Total %>
<p>
Add This Many: <asp:TextBox id="MyTextBox" runat="server" />
<asp:Button OnClick="DoSomething" Text="Go" runat="server" />
<MyStuff:Footer runat="server" />
</form>
</body>
</html>

Code behind:

public class DumbCalculatorPage : Page {
public int Total {
get {
if(ViewState["Total"] == null) {
ViewState["Total"] = 0;
}
return((int) ViewState["Total"]);
}
set {
ViewState["Total"] = value;
}
}

protected void DoSomething(object sender, EventArgs e) {
Total += int.Parse(MyTextBox.Text);
}

protected TextBox MyTextBox;
}

Now, wouldn't it be great to be able to change that aspx page to this, and
still have it compile and work with the same code behind class:

<%@ Page Inherits="DumbCalculatorPage" %>
<%@ Register TagPrefix="MyStuff" TagName="HeaderFooter"
Src="HeaderFooter.astx" %>

<html>
<head>
<title>Stupid Dumb Calculator</title>
</head>
<body>
<form runat="server">
<MyStuff:HeaderFooter runat="server">
Sum: <%= Total %>
<p>
Add This : <asp:TextBox id="MyTextBox" runat="server" />
<asp:Button OnClick="DoSomething" Text="Go" runat="server" />
</MyStuff:HeaderFooter>
</form>
</body>
</html>

You'll noticed that I've invented a new extension: "astx" T for template (I can't think of a better name, sorry).
What does an astx look like? very similar to ascx with a couple new tags:

<%@ TemplateControl ... %>

<table>
<tr>
<td>Header top</td>
</tr>
<tr>
<td>
<%@ ParentScope %>
</td>
</tr>
<tr>
<td>Footer row</td>
</tr>
</table>

How would this work? Well the TemplateControl would need two controls
collections, HeaderControls and FooterControls. And two Render methods
RenderHeader and RenderFooter. (The inner controls defined on the page
belong to the parent! It doesn't need to reference them.) During the
render phase of the page, the page would have to call RenderHeader, then
render the inner controls where the ParentScope tag is, then RenderFooter.

Now if you are talking about a static header and footer like my example, it seems like alot of extra work to change the framework to support this. But imagine a more complex control, like a tab control that has tabs and that is rendered as a table around it's contents. Then add properties to the tab
control. Add a property of tab alignment: TabAlignment="Top" versus
TabAlignment="Bottom" or TabAlignment="Right". Then add data binding to the tab control to determine what tabs to show, and events for clicking on the
tab links. Now the header and footer are very closely tied together, and do some neat stuff. The idea of this kind of Template becomes much more
interesting.

Implementing this as a templated control we loose our render blocks and
scoping. Why should the page have to search the template control for it's
inner text box? Why can't I use that simple render block?
Implementing this as two separate controls, we loose the connection between header and footer. It's tough to find out where our td/tr/table mismatches are between header and footer in different controls. Properties for the
header and footer aren't tied together in any way if they affect the
rendering.

Have I gone insane? Or is this a good idea? Or is there a similar way to
do this already that I am overlooking that does what I want? Is there a
reason this wouldn't work? (Seems the control hierarchy would be a bit odd :)

I just keep running into this and I want a better solution than the current template control implementation.

Nov 18 '05 #3
So shortly after I wrote this piece of garbage, I noticed that the PlaceHolder control does almost exactly what I want, except it doesn't render anything itself. It seems that a control that renders it's own content wouldn't be that much harder to do

It seems that the PlaceHolder control has a PlaceHolderControlBuilder class in the framework it's using to parse it's content. Anyone have any ideas on how it does what it does? The control builders seem to be less than well documented :)
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jez | last post by:
I'm ashamed that I need to ask this question. I've been using PHP for almost a year now, and have used HTML extensively in the last few years. Often, when I create a new site, I use include() to...
2
by: Salad | last post by:
Is there a way to determine which section of a form a control is located in code....besides using the tag property?
0
by: John Crowley | last post by:
I keep running into this over and over again... I want a block server control that renders a header and footer, and child controls in between. But I don't want a templated control, for the...
2
by: Nicholas | last post by:
Here is the issue: 1. I would like to create an ASP.Net/C# control to append a dynamic header and footer to **every** web page (depending on the page the content of each will vary). I can...
0
by: 00_ChInkPoIntD12 | last post by:
Is there any box wrapping control? so that I can put stuff in the box so that it looks more professional in a page. I am not sure what they call. It seems stupid to me to use "Header" and...
3
by: Dabbler | last post by:
is there a way to show the header even when GridView is empty? the page looks kind of bare with just empydatatext or emptyrowtemplate. Thanks.
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
0
by: Matthias | last post by:
Hi all, I have a problem with XSL FO. I wrote a handbook for my application in XML and formats it with xsl:fo (FOP) for PDF output. The handbook has some chapters. I have to write the actual...
2
by: ~john | last post by:
I'm trying to get my header to have 2 images, one for the top left and one for the top right. Here's a link to my page... http://levelwave.com/dev/div/index.html and will eventually be...
6
by: G | last post by:
Hello Friend, I am newly migrated from ASP to ASP.NET. When i am using ASP i used have a folder with named includes where i store header. asp and footer.asp pages. and i use <!-- #include...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.