标记里面的。开始时页面上只使用一个这个选择人员的用户控件时没有问题,但是如果页面上使用了2个或者多个这个选择人员的用户控件时,就出现脚本错误了。检查了一下,原来是使用多个时,页面上有同名的JavaScript方法,每次调用时只有调用后面的那个JavaScript方法,前面的那个方法就不起作用了。解决办法是:将JavaScript方法写在后台的cs文件里面,不用写在页面上。
Code
stringscript="<script>"+"\r\n";
script+="functionEmployeeChoose(SingleChoose,HideSelectValue,SelectName){"+"\r\n";
script+="varselectValue=document.all.item(HideSelectValue).value;"+"\r\n";
script+="varfeatures='help:no;status:yes;scroll:no;dialogTop:(srceen.availheigh/2)-250;dialogLeft:(screen.availwidth/2)-315;dialogWidth:450px;dialogHeight:330px;';"+"\r\n";
script+="varreturnValue=window.showModalDialog('/UserControl/StaffChooseList.aspx?SelectValues='+selectValue+'&SingleChoose='+SingleChoose,'',features);"+"\r\n";
script+="if(returnValue!=undefined){"+"\r\n";
script+="document.getElementById(HideSelectValue).value=returnValue.split('|')[0];"+"\r\n";
script+="document.getElementById(SelectName).value=returnValue.split('|')[1];"+"\r\n";
script+="}"+"\r\n";
script+="}"+"\r\n";
script+="</script>"+"\r\n";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"EmployeeChooser",script);
前台调用时:<span style="cursor: hand" id="EmpChoose" onclick ="EmployeeChoose('<%=SingleChoose %>','<%=HideSelectValue.ClientID %>','<%=SelectName.ClientID %>');">
这样就可以避免出现javascript同名函数的问题了。
优质内容筛选与推荐>>
1、Android ImageSwitcher2、博客园开博!3、css中的盒子模型4、jmeter --自动化badboy脚本开发技术5、LeetCode(50):Pow(x, n)