我的需求是在一个UserControl的OnPrerender里面注册一些style在head里面。
首先需要创建一个Style对象,然后设置具体的style的定义,再使用Page.Header.StyleSheet.CreateStyleRule()函数就可以注册成功了。
页面的head里面会生成对应的定义。现在的问题是,Style类里面的属性只可以设置Font,Color这些,我的需求是写position:absolute;z-index=1这样的定义。我找了半天不知道怎么使用这个API实现。请知道的朋友帮忙指点一下,谢谢。

解决方案 »

  1.   

    1、定义:protected Microsoft.Web.UI.WebControls.CssCollection sty_Default = new Microsoft.Web.UI.WebControls.CssCollection();  //默认2、加属性sty_Default.Add("position", "absolute");
    sty_Default.Add("z-index", "1");
    sty_Default.Add("padding", "1px 1px 1px 1px");
    sty_Default.Add("font-family", "Arial");
    sty_Default.Add("font-size", "12px"); 
    sty_Default.Add("text-decoration", "none");
    sty_Default.Add("font-weight","normal");  3、赋值引用
      

  2.   

    我现在的需求是在<head>里面声明<style type="text/css">...</style>
    而不是要在节点的style属性里面加。