CssStyleCollection.Item Property (HtmlTextWriterStyle)
Gets or sets the specified HtmlTextWriterStyle value for the HTML server control.
Assembly: System.Web (in System.Web.dll)
Parameters
- key
- Type: System.Web.UI.HtmlTextWriterStyle
Property Value
Type: System.StringThe value key; otherwise, null, if key is not in the server control's collection.
Style items that are added programmatically to a CssStyleCollection collection for a control with the Item property or the Add method that take an HtmlTextWriterStyle enumeration value as an input are included in the count of style items that are returned with the Count property and are included with the string literal that is returned with the Value property. These attributes are strongly typed. If the cascading style sheet attribute that you want to add to a server control exists in the HtmlTextWriterStyle enumeration, use these strongly typed methods. If the attribute you want to add does not exist in the HtmlTextWriterStyle enumeration, use the Item property or the Add method.
Trying to access an HtmlTextWriterStyle enumeration value in the CssStyleCollection of a control that has not been added or to access a CSS attribute that has been added with the Item property or the Add method, returns null using the Item property.
The following code example uses the Item property to return the value of a style that is set on a HtmlInputText control.
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) MyText.Style.Add(HtmlTextWriterStyle.Width, "200") FirstMessage.Text = "The text box font color is: " _ & MyText.Style("color") & "<br />" _ & "The text box width is: " & MyText.Style(HtmlTextWriterStyle.Width) End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>CssCollection This Example</title> </head> <body> <form id="form1" runat="server"> <div> <input id="MyText" type="text" value="Type a value here." style="font: 14pt Verdana; color: blue;" runat="server"/> <br /> <asp:Label id="FirstMessage" runat="server"/> </div> </form> </body> </html>
Available since 2.0