本文介绍了不在母版页中应用css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的母版页上有一个asp文字控件。关于该控件的文字,我附上了

< link type =text / css =stylesheethref =〜/ css / skin.css> 但是即使我尝试在Page_Init,Page_PreRender和最初的page_load事件中应用此控制文本,此链接也不应用css。



请建议我在哪里可以进行更改。

Hi all,

I have a asp literal control on my master page. On that control's text I attached
<link type="text/css" rel="stylesheet" href="~/css/skin.css" > but this link is not applying css even if I tried to apply this control text in Page_Init,Page_PreRender,And Initially on page_load events.

Please suggest me where i can make changes.

推荐答案



Hi all thanks for your time and suggestion...
I got the solution. I was applying css on literal's text property in Page_PreRender event.
So that in rendered output of page link was displayed like this: &lt;link type="text/css" rel="stylesheet" href="~/css/skin.css" &gt; so that css path was not getting found.
Solution for this is:
<pre lang="cs">protected void Page_Init(object sender, EventArgs e)
    {
        //litSkinStyle.Text = Common.auto_version(&quot;css/skin.css&quot;);
        var link = new HtmlLink();
        link.Href = Common.auto_version(&quot;css/skin.css&quot;);
        link.Attributes.Add(&quot;rel&quot;, &quot;stylesheet&quot;);
        link.Attributes.Add(&quot;type&quot;, &quot;text/css&quot;);
        Page.Header.Controls.Add(link);
    }</pre>

Now I'm giving relative path which is correctly rendered in output and css is applied.
I used this way because I have done auto version of css.


这篇关于不在母版页中应用css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:58