开发者

can not resolve style from master page's pageload

I have a page login.aspx in 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 st开发者_运维知识库yles from the masterpage's pageload event. I analysed the problem found that because my login.aspx is not in root folder, but in a folder which is inside root folder.

How do I run masterpage's pageload event in login.aspx?


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 :-)


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.


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.


The problem is that the section of the markup is located in the Master Page, so the reference to the StyleSheet cannot be made

Dim link As New HtmlLink
link.Href = "LocationOfStyleSheet.css"
link.Attributes.Add(HtmlTextWriterAttribute.Rel.ToString(), "stylesheet")
Page.Header.Controls.Add(link)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜