在用户控件中撰写JS时控件的客户端ID问题
其实有两种方法,一是在代码中生成JS脚本
第二种办法,就是直接在ASPX文件里撰写JS脚本,对于控件ID的问题,可以用<%# this.ID+"_"+控件ID %>的方式动态生成,只要在代码中调用一下PAGE.DATABIND()即可
下面是示例JS代码
<script language=javascript>
function CheckLoginForm()
{
with(document.forms[0])
{
if(<%# this.ID+"_TbUserName" %>.value=="")
{
alert("Must input username");
return(false);
}
}
}
</script>
发送到客户端后的JS代码
<script language=javascript>
function CheckLoginForm()
{
with(document.forms[0])
{
if(HomeNavigator_TbUserName.value=="")
{
alert("Must input username");
return(false);
}
}
}
</script>
结果证明,效果非常棒
第二种办法,就是直接在ASPX文件里撰写JS脚本,对于控件ID的问题,可以用<%# this.ID+"_"+控件ID %>的方式动态生成,只要在代码中调用一下PAGE.DATABIND()即可
下面是示例JS代码
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
结果证明,效果非常棒