Best Methodology For Creating A Head For Web Page

  • Thread starter Thread starter Stephen Adam
  • Start date Start date
S

Stephen Adam

Hi there,

I am developing a web site with a number of pages, I want each page to have
the same heading section which will include both the raw html and vb.net
code which handle rollovers for some images which will also be included.

My initial feeling on how to do this would be to create a base class web
page and then inherit it with all the HTML response.writing and image
rollover code already there. Problem being that my page already inherits the
System.Web.UI.Page class so I cant do it that way.

What is the recommended way of including the same basic code and html for
each page on a site? Web pages on sites nearly always have the same header
and menu information on each page, how should this be done in a nice proper
OO way?

Hope I haven't opened up a can of worms, I know its a general question with
lots of possible answers but it would be good to be pointed in the right
direction :)


Thanks


Steve
 
Most people just use an include statement and have the code in the \includes
directory.



--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
Stephen Adam said:
Hi there,

I am developing a web site with a number of pages, I want each page to
have
the same heading section which will include both the raw html and vb.net
code which handle rollovers for some images which will also be included.

My initial feeling on how to do this would be to create a base class web
page and then inherit it with all the HTML response.writing and image
rollover code already there. Problem being that my page already inherits
the
System.Web.UI.Page class so I cant do it that way.

Sure you can. Just create your own base Page class inheriting
System.Web.UI.Page, and inherit from that instead.
What is the recommended way of including the same basic code and html for
each page on a site? Web pages on sites nearly always have the same header
and menu information on each page, how should this be done in a nice
proper
OO way?

Page inheritence or Web user controls. See, eg

http://www.codeproject.com/aspnet/page_templates.asp

and

http://msdn.microsoft.com/library/d...l/vbwlkwalkthroughcreatingwebusercontrols.asp

David
 
One Handed Man ( OHM - Terry Burns ) said:
Most people just use an include statement and have the code in the
\includes directory.

Include is the old ASP way, and it requires you to put code in your ASPX
files, which is a pain since you don't get intellisense and it doesn't
compile until the user hits it.

Yuck.

David
 
Thanks for all the tips guys, i've now created a base web page class which
extends System.Web.UI.Page which is great and everything... But, i've got
all my rollover code in the page_load sub of my base web page class. Now on
many pages i'm going to want to add other bits and bob's to the page_load
sub. How can I do this? You can extend a class but not a method (sub), I
suppose I could over-ride it but then i'd have to enter in all the base
class rollover code again which kinda defeats the object.

Thanks again
 
LOL, Oh well, never mind, there are other ways like creating your own page
class. Next year you wont have this issue with 2005 but I dont suppose
that's gonna help you right now.



--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
Stephen,
Page_Load is an event, you can have multiple event handlers handle the
event. Which means you can have your base page handle it & your derived
pages also handle it.

What I normally do is override the Page.OnLoad method instead, being certain
to call MyBase.OnLoad and do any "event handling" in the OnLoad method.

Page.OnLoad raises the Load event.

I normally override the On<event> methods when I am handling an event
internally in a derived class. I normally handle the <event> when I am
handling an event externally, when the object is contained in another
object.

For details on the relationship between <event> and On<event> see:

The "Design Guidelines for Class Library Developers" has some information on
implementing events in both C# & VB.NET.

http://msdn.microsoft.com/library/d.../cpgenref/html/cpconEventNamingGuidelines.asp

http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconEventUsageGuidelines.asp

Note: within VB.NET you can simply use RaiseEvent rather then checking to
see if a delegate variable is Nothing and invoking the delegate variable...

Hope this helps
Jay
 
Stephen,

I never did what you ask, however in this I would probably for sure use a
shared class, which will function very well for problems like this in a
webapplication.

The shared class belongs to the application so will be loaded only with the
first page (session) that is used at that time and after can be used for all
pages for every session that is active.

I hope this gives an idea?

Cor
 

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

Back
Top