使用者控制項裡的CSS該如何定義

來源:互聯網
上載者:User

使用者控制項如果要集中定義類似
<style type="text/css">
    .C {border-right:1px #D9AE7F solid;border-bottom:1px #D9AE7F solid;cursor:pointer;font-family:arial;font-weight:bold;height:23px;background:#FFF7DD none repeat scroll 0 0; line-height:20px;}
    #ctem td {border-bottom:1px solid #F0F0F0;color:black;height:25px;}
    #ctem a:link,#cctvitem a:active,#cctvitem a:visited {color:black;text-decoration:none;}
    #ctem a:hover {color:red;text-decoration:underline;}
    .TMSpan {cursor:pointer;display:inline;width:70px;margin:3px 2px 0px 2px;height:16px;border-left:1px solid #D9AE7F;border-right:1px solid #D9AE7F;border-top:1px solid #D9AE7F;text-align:center;font-weight:bold;}
</style>
這種CSS怎麼辦。

如果是寫在控制項中,不符合規範,雖然一般情況下也起作用,但如果是動態載入,如AJAX載入這個使用者控制項,就不行了。

如果由調用頁預先寫在頁頭,當然沒問題,但控制項的意義就打了折扣。

可以使用如下方法:

控制項代碼:
    const string STYLE = @"<style type=""text/css"">
    .C {border-right:1px #D9AE7F solid;border-bottom:1px #D9AE7F solid;cursor:pointer;font-family:arial;font-weight:bold;height:23px;background:#FFF7DD none repeat scroll 0 0; line-height:20px;}
    #ctem td {border-bottom:1px solid #F0F0F0;color:black;height:25px;}
    #ctem a:link,#cctvitem a:active,#cctvitem a:visited {color:black;text-decoration:none;}
    #ctem a:hover {color:red;text-decoration:underline;}
    .TMSpan {cursor:pointer;display:inline;width:70px;margin:3px 2px 0px 2px;height:16px;border-left:1px solid #D9AE7F;border-right:1px solid #D9AE7F;border-top:1px solid #D9AE7F;text-align:center;font-weight:bold;}
</style> ";

protected void Page_Load(object sender, EventArgs e)
    {
        //控制項自有CSS
        this.Page.Header.Controls.Add(new LiteralControl(STYLE));
    }

這樣控制項的CSS就會出現在調用頁的<head/>裡了。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.