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;}}
转载于:https://www.cnblogs.com/asdyzh/p/9757614.html