473,385 Members | 1,325 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,385 software developers and data experts.

Custom Page Control

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
4 1538
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michel | last post by:
On an empty ASP.NET page, a placeholder is added. On this page, a literal is added dynamicly, through the placeholder. On the same page, a custom control is dragged. The same custom control is...
3
by: Lloyd Sheen | last post by:
I have a piece of functionallity that is replicated on several pages. This would be a good candidate for a custom control right? Well I found a couple of tutorials (none really helpful) so I...
1
by: Lamont Adams | last post by:
Hi all, I've created numerous custom controls of varying complexity, but I've been on this problem for a day and a half, and I can't figure this mystery out. I hope one of you kind folks can...
1
by: Chris Newby | last post by:
I have a custom control that derives from the WebControls.Panel class. In a given ASPX document, I have an instance of my custom control with ID set to "MyControl". Then I put a...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
0
by: Pavan | last post by:
My name is Pavan and I am a software engineer working on ASP .Net web development. Currently I am using .Net 2.0 Professional Edition to develop my web pages. I have a problem
5
by: Alan Silver | last post by:
Hello, I have a products page that takes a product ID in the query string. Based on the product details (from a database), the page then loads up one of a number of custom controls, calls a...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
2
by: Michal Valent | last post by:
I would like to fire some custom server control event before Page_Load event like this (from the trace of an aspx page) : Trace Information Category Message From First(s) From Last(s) aspx.page...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
1
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.