Attributes.Add用途與用法

來源:互聯網
上載者:User

標籤:label   tty   attr   param   arm   add   並且   .exe   varchar   

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中引自:http://hi.baidu.com/sbdnpgk/blog/item/617ddb1a8b0de1128618bfbc.htmlButton1.Attributes.Add()方法小結 //首先要在PageLoad()事件中註冊屬性    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            Button1.Attributes.Add("onclick", "return checkSame()");//為Button1添加onclick()事件 ,Button為伺服器控制項        }//注意:checkSame()這是一個寫在aspx面頁的js函數,必須有傳回值,為:true 或 false    }//接著寫Button1的onclick事件,如果剛才的checkSame()返回為true則招行下面的事件,否則不執行     protected void Button1_Click(object sender, ImageClickEventArgs e)    {        SqlParameter[] Params = new SqlParameter[2];        Params[0] = dbs.MakeInParams("@uid", SqlDbType.VarChar, 10, Session["Uid"].ToString());        Params[1] = dbs.MakeOutParms("@Upwd", SqlDbType.VarChar, 10);        if (dbs.ExecuteNonQuery(CommandType.StoredProcedure, "selectPwd", Params) > 0)        {            string userPwd = Params[1].Value.ToString();            if (userPwd != this.old_pwd.Text)            {                Response.Write("<script>alert(‘原始密碼錯誤!‘)</script>");            }            else            {                           }        }        else         {            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert(‘操作失敗!‘)</script>");        }    }//呵呵。。再寫一個js試例吧      function checkSame()    {      var Obj1=document.getElementById ("new_pwd").value;      var Obj2=document.getElementById ("re_new_pwd").value;            if(Obj1!=Obj2)       {          alert("兩次密碼輸入不一致!");          document.getElementById("new_pwd").focus();          return false;       }       else       {         return true;       }    }

Attributes.Add用途與用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.