以下是引用片段: <script language="VB" runat="server" > Sub Page_Load(Sender As Object, E As EventArgs) MyText.Style("width") = "90px" Response.Write(MyText.Style("width")) End Sub </script> <input type="text" id="MyText" runat="server"/>
下面的例子显示了如何编程使用Style集合属性来控制HTML服务器控件的样式:
以下是引用片段: <script language="VB" runat="server"> Sub Page_Load(Src As Object, E As EventArgs) Message.InnerHtml ;= "<h5>Accessing Styles...</h5>" Message.InnerHtml ;= "The color of the span is: " ;MySpan.Style("color") ;"<br>" Message.InnerHtml ;= "The width of the textbox is: " ;MyText.Style("width") ;"<p>" Message.InnerHtml ;= "MySelect's style collection is: <br><br>" Dim Keys As IEnumerator Keys = MySelect.Style.Keys.GetEnumerator() Do While (Keys.MoveNext()) Dim Key As String Key = CStr(Keys.Current) Message.InnerHtml ;= "<li> " Message.InnerHtml ;= Key ;"=" ;MySelect.Style(Key) ;"<br>" Loop End Sub Sub Submit_Click(Src As Object, E As EventArgs) Message.InnerHtml ;= "<h5>Modifying Styles...</h5>" MySpan.Style("color") = ColorSelect.Value MyText.Style("width") = "600" Message.InnerHtml ;= "The color of the span is: " ;MySpan.Style("color") ;"<br>" Message.InnerHtml ;= "The width of the textbox is: " ;MyText.Style("width") End Sub </script>