how to set Link tag for style sheet in base page

M

moondaddy

I've build a basepage that will be used for all the pages in my website. I
created a propery in the base page called Title like this:

Private baseTitle As HtmlGenericControl
Protected Property Title() As String
Get
Return baseTitle.InnerText
End Get
Set(ByVal Value As String)
baseTitle.InnerText = Value
End Set
End Property

and it sets it's value in an htmlcontrol like this:

' Page Title
baseTitle = New HtmlGenericControl("title")
baseTitle.ID = "baseTitle"
Me.Controls.Add(baseTitle)


This way I can set the page title from the page that inherits the base page.
how can I do a similar thing to set the page's stilesheet in the link tag?

I will also be wanting to reference the script files the same way.

Any good recomendations?
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

From your description, what you want to do is modify the <head> area of the
ASP.NET web page at runtime via code, yes?

As for this problem, currently we haven't any buildin means to do so. Based
on my research, most ones make use of the Literal control to represent the
<head> area of an asp.net web page.
set the
<head runat="server" id="xxx" >
and then use a LiteralControl in code behind to reference it. Also, if you
want to perform a common framework on handling a group of pages. We still
need to integrate this skill together with the PageControler(base page)
pattern. And below are some certain web resources discussing on the
similiar problem:

#ASP.NET Page Templates - Using Inheritance
http://www.codeproject.com/aspnet/page_templates.asp

#Dynamically Adding <HEAD> Content with ASP.NET
http://dotnetjunkies.com/WebLog/bsblog/archive/2004/02/11/7052.aspx

An improvement to RegisterClientScriptBlock
http://www.codeproject.com/aspnet/scriptregister.asp?print=true

Hope helps. 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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
M

moondaddy

Thanks but these just aren't helping me. I've already gone over
http://www.codeproject.com/aspnet/page_templates.asp numerous times and the
others are about the same. for one thing, they're all in c# and although I
can understand the concepts, making it a reality in vb.net is another thing.
even if I use the translation tool you recommended doesn't help much as it
often makes mistakes which ends up consuming lots of time to (try) to fix,
and makes things more confusing. All of this aside, my biggest problem is
one KEY thing. I understand how to use the literalcontrol to create the
html, header, etc... tags. BUT, how do I pass a value into a property from
the derived page and use this property to customize the header tag? These
tags get created when the pages are initialized which happens before I can
pass in a value from the derived class (as far as I know...). This is my
missing link Can you clearify this for me?

Thanks again!
 
M

moondaddy

I found it. It never fails. I make a post like this and then I find it
myself. I was able to get the overall mechanics from the links provided in
the above posts. The way to pass in custom property values to be used in
the header tag creation when the page is initialized is in the derived page
like this:

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
KeyWords = "Photo Charms, Italian Charms, Mother's Day"
Description = "Best Darn Links Around"
Title = "Hello World"
Link = "<LINK href='Styles/Main.css' type='text/css'
rel='stylesheet'/>"
End Sub

This in WebForm1.aspx which inherits from BasePage.aspx. The properties
KeyWords, Description, Title and Link are used in BasePage to set the header
tag as links in this thread show. The KEY point here is that "OnInit" in
WebForm1.aspx fires before anything else including "OnInit" in BasePage
which allows me to pass in all the custom values I want to use for
initializing BasePage.
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

Thanks for your followup. I'm glad that you've finally figured out the
problem. Also, I think it'll be nice if you would share some of your
solution maybe a demo page here so that some other ones who have the same
problem maybe easy to find the resources here. Do you think so? 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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top