在页面加载的时候使用:
控件名.Attributes.Add("属性名", "为属性添加值");
如,使用javascript为listbox控件添加双击删除事件:
前台:
<script language="javascript" type="text/javascript">
function change() {
if (document.getElementById("lbDeparName").length == 0)
return (false);
var index = document.getElementById("lbDeparName").selectedIndex;
if (index < 0)
return (false);
document.getElementById("lbDeparName").remove(index);
}
</script>
<asp:ListBox ID="lbDeparName" Width="160px" Height="210px" runat="server"></asp:ListBox>
后台:
protected void Page_Load(object sender, EventArgs e)
{
lbDeparName.Attributes.Add("onDblClick", "change()");
}