By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,567 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,567 IT Pros & Developers. It's quick & easy.

Custom Page Control

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.N...e-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.)


Nov 19 '05 #2

P: n/a
You can do this with help of page template, check out this article to know
how to implement page template in asp.net
http://www.microsoft.com/india/msdn/articles/87.aspx

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"James Thomas" <Ra****@nospam.nospam> wrote in message
news:10*************@corp.supernews.com...
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

Nov 19 '05 #3

P: n/a
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

James Thomas wrote:
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


Nov 19 '05 #4

P: n/a
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....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.)

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.