Attributes.Add用途與用法

 

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中

發佈了8 篇原創文章 · 獲贊 5 · 訪問量 28萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章