| |||||||
WebControl.Attributes PropertySystem.Web.UI.WebControls Namespace WebControl Class Returns the collection of attributes applied to a Web control. Also sets or retrieves the individual attribute items in the collection. Syntax
This property can only be used programmatically; it cannot be set when declaring the control. Property ValueA System.Web.UI.AttributeCollection of name and value pairs. When accesing individual attributes in the collection:
This property is read/write. RemarksThe Attributes collection comprises the list of all attributes declared within the opening tag of a Web server control. This enables object-model access to each of the attributes defined for the control. Like any collection in ASP.NET, the individual attribute items can be accessed using either the attribute's name or ordinal index ( the position of the item in the order in which the items have been added to the list ). And as with other collections, attributes may dynamically be added to or removed from the collection.
This feature requires Microsoft® Internet Explorer® 4.0 or later. ExampleThe following example demonstrates how to enumerate the items of the AttributeCollection object retrieved from a Web control. 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>
The following example illustrates how the Attributes property of a Web control can be used to run a client-side script command when the TextBox control loses focus. <html>
<head>
<script language = "C#" runat = "server">
void Page_Load ( Object src, EventArgs e ) {
TextBox1.Attributes [ "onBlur" ] = "javascript:alert" +
" ( 'This message will appear each time the TextBox loses focus.' ) ";
}
</script>
</head>
<body>
<form runat = "server">
<asp:TextBox id = "TextBox1" size=40 runat = "server"
Text = "Click here and then tap out of this text box" />
</form>
</body>
</html>
See AlsoWebControl Members Base Web Control Properties |
| ||||||
Check out related books at Amazon
© 2000-2008 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 aspxtreme