asp.net.ph

AttributeCollection Class

System.Web.UI Namespace


Provides object-model access to all attributes declared in the opening tag of an ASP.NET server control element. This class cannot be inherited.

AttributeCollection Class Members

Collapse   Constructors

Visibility Constructor Parameters
public AttributeCollection ( StateBag bag )

Collapse   Properties

Visibility Name Value Type Accessibility
public Count Int32 [ Get ]
public CssStyle CssStyleCollection [ Get ]
public Item ( String key ) String [ Get , Set ]
public Keys ICollection [ Get ]

Collapse   Methods

Visibility Name Parameters Return Type
public Add ( String key , String value ) Void
public AddAttributes ( HtmlTextWriter writer ) Void
public Clear ( ) Void
public Equals ( Object o ) Boolean
public GetHashCode ( ) Int32
public Remove ( String key ) Void
public Render ( HtmlTextWriter writer ) Void

Remarks

Attributes' case-sensitivity depends upon whether the StateBag class from which it inherits is case-sensitive or not. They return a String object as their value. If there are no attributes in the collection, they return a null reference ( Nothing in Visual Basic ).

Attributes on an HTML server control are programmatically accessible through the HtmlControl.Attributes property, which is inherited by all HTML server controls. The .NET Framework treats HTML attributes as properties of the HTML server control to which they belong.

You can also add attributes to a Web server control through the WebControl.Attributes property, which is inherited by all Web server controls. Attributes stored in this collection for a Web server control do not correspond to the strongly typed properties found on the specified Web server control.

Example

The below code shows how to enumerate the items of the AttributeCollection object retrieved from an HtmlControl. Note that the attributes stored in this collecion reflect only the arbitrary properties that do not correspond to the properties defined in the .NET Framework for the control.

<script language="C#" runat="server">
string atts;

void showAttributes ( object src, EventArgs e ) {
   IEnumerator attribs = greeting.Attributes.Keys.GetEnumerator ( );
   while ( attribs.MoveNext ( ) ) {
      string key = ( string ) attribs.Current;
      atts += key + " = " + greeting.Attributes [ key ] + "<br>";;
   }
   message.Text = atts;
}
</script>

 Show me 

See Also

HtmlControl.Attributes   WebControl.Attributes Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph