Attributes.Add()

在前台用JS写的脚本方法,除了能够直接用在前台控件的属性中,还能够在后台运用。 即在后台页面加载时,调用JS方法。

语法格式有两种,编程

以下:this

 1.第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”);事件

如:一个按钮控件Button1.Attributes.Add(“onclick”,“return confirm('确认?')”);io

 

2.另外一写法:控件ID名.Attributes["事件名称"]=“JS方法";function

如:前台写了一个JS方法: function ISCheck(){。。。。。。}; Button1.Attributes[“onclick”]="ISCheck()";class

 

编程实战:后台

this.txtBeginDate.Attributes["onclick"] = "return showCalendar('" + this.txtEmpName.ClientID + "','y/mm/dd')";
this.txtBeginDate.Attributes.Add("onclick", "return showCalendar('" + this.txtEmpName.ClientID + "','y/mm/dd')");cli

//以上两种方法是等效的语法


this.txtBeginDate.Attributes["readonly"] = "true";     //在txtBeginDate中添加readonly为True的属性。方法

this.txtBeginDate.Attributes.Add("readonly", "true");  //等效的写法

本站公众号
   欢迎关注本站公众号,获取更多信息