Custom Page Control

J

James Thomas

Hello -

I am attempting to override the Page control so it outputs a simple
copyright message at the bottom of every page.

The problem I'm running into is that it puts said message below the
</html> tag, which is not compliant.

How do I force this message to appear just above the </body> tag while
keeping everything else the same?

Here's how I'm dealing with it so far:
namespace MyNamespace
{
public class CopyPage : System.Web.UI.Page
{
protected override void Render(HtmlTextWriter output)
{
base.Render(output);

output.AddAttribute("id", "copyright");
output.RenderBeginTag("span");
output.Write("Some Company - All rights reserved");
output.RenderEndTag();
}
}
}


Thanks,

James
 
S

Steven Cheng[MSFT]

Hi James,

From your description, you're wanting to generate a base page class which
will output some common Page Header or Footer html contents on all the
derived pages, yes?

As for the problem you encountered, I think we have the following approachs:
1. Don't change our derived pages' aspx template, and just make use the
base page's Render method. We can use the base.Render to get the page's
default output html content and them locate the <body>...</body> section
and insert our header and footer in it(maybe around the <form> ..</form>).
Such as :

protected override void Render(HtmlTextWriter writer)
{

StringBuilder sb = new StringBuilder();

HtmlTextWriter htw = new HtmlTextWriter(new StringWriter(sb));

base.Render(htw);

//parse the sb.ToString() and modify it
}

We may need to use regex to do some string parsing.

2. We can also use OO based page inheritance and make the footer and header
as controls in the page's control collection and put all the controls in
derived page inside our base page's Form control.
Here are some tech article dicusssing on such approachs:

#Easy ASP.NET Page Templates
http://www.devarticles.com/c/a/ASP.NET/Easy-ASP.NET-Page-Templates/1/

#Do more with your ASP.NET Page Template
http://www.codeproject.com/aspnet/pagetemplates.asp

However, this may need us to modify our derived page's aspx template so as
not to include <html> <body> tags in it.

Hope these help. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

James Thomas

Thanks to Steven and Saravana, I was able to use the articles they both
pointed to to generate a page template. As long as I was at it, I
created a fully functional page template that generates my header and
side navigation bar as well, then fills in a portion in the middle with
my content.

Thanks!

Fully integrated and functional master pages would have been nice here
- I could have avoided a lot of the work I went through (can't wait for
ASP .NET 2.0!) but even so, I have them working now so I appreciate the
information!

Thanks,

James
 
S

Steven Cheng[MSFT]

Hi James,

Thanks for your followup. Glad that our suggestions are of assistance. Yes,
the MasterPage feature in ASP.NET 2.0 is attractive. Though it is under
beta now, if you're interesting in it, you can try the beta version on your
test box.

Here is the start link in the msdn for asp.net 2.0

http://msdn.microsoft.com/library/en-us/dnvs05/html/SKinVS2005.asp?frame=tru
e

You can also find hundreds of other articles introducing them. Enjoy them:)

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top