Attributes.Add用途与用法

来源:互联网 发布:免费点餐软件 编辑:程序博客网 时间:2024/04/29 22:29
 

Attributes.Add("javascript事件","javascript语句");

如:

this.TextBox1.Attributes.add("onblue", "window.Label1.style.backgroundColor='#000000';");

this.TextBox1.Attributes.Add("onblur","this.style.display='none'");

javascript事件:

onClick     鼠标点击事件,多用在某个对象控制的范围内的鼠标点击

onDblClick    鼠标双击事件

onMouseDown    鼠标上的按钮被按下了

onMouseUp    鼠标按下后,松开时激发的事件

onMouseOver 当鼠标移动到某对象范围的上方时触发的事件

onMouseMove    鼠标移动时触发的事件

onMouseOut 当鼠标离开某对象范围时触发的事件

onKeyPress    当键盘上的某个键被按下并且释放时触发的事件.[注意:页面内必须有被聚焦的对象]

onKeyDown    当键盘上某个按键被按下时触发的事件[注意:页面内必须有被聚焦的对象]

onKeyUp   当键盘上某个按键被按放开时触发的事件[注意:页面内必须有被聚焦的对象]

 

Attributes.Add添加多了之后会影响一定速度,Attributes和Attributes.CssStyle被自动保存到ViewState中后,除了ViewState体积急增后,PostBack时Load ViewState的负担也同时增大了。

 在下面的事件中添加,如下形式:
protected override void Render(HtmlTextWriter output)
{
    this.Attributes["abc"] = "123";
    this.Attributes.CssStyle["abc-style"] = "123-style";
    output.Write(Text);
}
  就不会再将Attributes和Attributes.CssStyle保存到ViewState中

原创粉丝点击