views:

167

answers:

3

i have a page login.aspx in a a folder which is linked to masterpage..in the page load event of masterpage i have added some styles.when i redirect to login.aspx it is just not able to get the styles from the masterpage's pageload event.i have analysed the problem and what i could make out it, is that because my login.aspx is not in root folder but in a folder which is inside root folder..so my isseue is to run masterpage's pageload event in login.aspx

A: 

If the code works when you move the code to your templatized page (not the but the one that uses it) then it suggests that you are using a relative link for the stylesheet.

I'd recommend using a relative URL off the root (something in the form of "/stylesheet.css") so that when you have pages that use the template, but in a subdirectory, it can resolve the stylesheet correctly.

casperOne
A: 

You can place all your style sheets in a folder structure as follows:

App_Themes/Style/mystylesheet.css

Then in your content ASPX pages, just add Theme="Style" to the page directives and ASP.NET will automatically resolve it for every page that you have :-)

IrishChieftain
A: 

I assume you're talking about CSS stylesheets, and not ASP.NET styles (themes).

In that case, you can using a tag like the following from your Master page:

<link runat="server" rel="Stylesheet" href="~/scripts/common.css"
    type="text/css" />

Or you can insert the same tag programmatically from your Page_Load() handler. However, in that case, it's best if you add the HtmlLink control to the Head control. Alternatively, you can add an ID to the control and use Visible="True" to control whether it appears in the generated markup.

RickNZ
Hi Rick, just bought your new ASP.NET book and it rocks! :-)
IrishChieftain
Thanks! Glad to hear that you're enjoying it.
RickNZ