您的位置:首页 > 编程语言 > ASP

ASP.NET 的 WebControl.Attributes 属性

2006-05-27 21:39 501 查看
WebControl.Attributes 属性

获取与控件的属性不对应的任意特性(只用于呈现)的集合。
[Visual Basic]
Public ReadOnly Property Attributes As AttributeCollection
[C#]
public AttributeCollection Attributes {get;}
[C++]
public: __property AttributeCollection* get_Attributes();
[JScript]
public function get Attributes() : AttributeCollection;

属性值
名称和值对的 System.Web.UI.AttributeCollection。

备注
Attributes 集合包含在 Web 服务器控件的开始标记中声明的所有属性的集合。这使您得以以编程方式控制与 Web 服务器控件关联的属性。您可以将属性添加到此集合或从此集合中移除属性。
注意 此属性用控件开始标记中集合中的所有属性来呈现,与浏览器设置无关。并非所有的浏览器都支持呈现的每个属性。不受支持的属性通常被浏览器忽略。

示例
[Visual Basic, C#, JScript] 下面的示例阐释当 TextBox 控件失去焦点时,可以如何使用 WebControl 的 Attributes 属性运行 Javascript 命令。
[Visual Basic]

<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>
<script language="VB" runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
TextBox1.Attributes("onblur") = "javascript:alert('Hello! Focus lost from text box!!');"
End Sub
</script>

</head>
<body>
<h3>Attributes Property of a Web Control</h3>
<form runat="server">

<asp:TextBox id="TextBox1" columns=54
Text="Click here and then tap out of this text box"
runat="server"/>

</form>
</body>
</html>
[C#]

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

<html>
<head>
<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs e) {
TextBox1.Attributes["onblur"]="javascript:alert('Hello! Focus lost from text box!!');";
}
</script>

</head>
<body>
<h3>Attributes Property of a Web Control</h3>
<form runat="server">

<asp:TextBox id="TextBox1" columns=54
Text="Click here and then tap out of this text box"
runat="server"/>

</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: