当前位置:编程学习 > C#/ASP.NET >>

里面是对一个body的属性进行server的一些设定,不过可以衍生到其他的一些htmlcontrol新手看看,或者有点...

答案:The first code snippet below uses the Attributes collection of the <body> tag (implemented as an HtmlControl object) to reference its standard HTML attributes. This method gives you programmatic access to any of the HTML attributes that you normally hard-code into your <body> tag.

The second method uses the Style object property of the HtmlControl object. By making calls to the Style object property's Add method, you can add custom styles to your <body> tag. These are implemented as an inline style tag when it is rendered to the browser.
Because of this, you may want to research whether the style you are going to implement is compatible with the browser you are targeting.

The techniques used here can be used to set the properties of any HTML control that does not have a Server Control equivalent. An example would be the <p> tag.


Sample code 1: Use the "Attributes" collection of the body tag


<%@ Page Language="C#" %>

<script language="C#" runat="server">
    protected void Page_Load(object sender, EventArgs e) {
        body.Attributes["BgColor"] = "#CCCCCC";
    }
</script>

<body id="body" runat="server">
    This is the body text.
</body>



Sample Code 2: Use the "Style" collection of the body tag


<%@ Page Language="C#" %>

<script language="C#" runat="server">
    protected void Page_Load(object sender, EventArgs e) {
        body.Style.Add("background-color","#CCCCCC");
    }
</script>

<body id="body" runat="server">
        This is the body text.
</body>



Notes:
Be sure to add the runat="server" attribute to your body tag and give it an ID

上一个:.Net边学边讲(一)
下一个:一个实现自定义event的文章。。。我还没有完全摸透。。不知道有没人有兴趣。。新手就不用看了,先学会走...

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,