日期:2014-05-18  浏览次数:20388 次

CustomValidator验证问题

<input id="txtbranchhidden" style="DISPLAY: none" type="text" name="Text1" runat="server">
  <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="checkbranch()" ErrorMessage="请选择分部负责人!" SetFocusOnError="True" Display="Dynamic"></asp:CustomValidator></td>


 function checkbranch(source,args)
 {  
  if (document.getElementById("rdcaltype2").checked)
  {
  if (document.getElementById("txtbranchhidden").value == "")
  {  
  args.IsValid = false;  
  }
  else
  {
  args.IsValid = true;
  }
  }
 }


提示"undefined"错误:args.IsValid 

请问怎么解决?

------解决方案--------------------
mark
------解决方案--------------------
checkboxlist 选择为空时的判断(customvalidator[用户自定义验证控件]的应用):
<script language="javascript" type="text/javascript">
function check(source,args)
{
var obj=document.getElementById('<%=this.huanjing.ID%>');//返回具有和属性id的值相同或相似的对象集合
var k,bol=false;
var ln=(obj.all.tags('input').length);//返回obj对象里具有“input”标签对象的集合
for(k=0;k<ln;k++)
{
//alert(" name:"+obj.all.tags('input')[k].name+"是否:"+obj.all.tags('input')[k].checked);
  
if(obj.all.tags('input')[k].checked) // obj对象里具有input标签对象键值为k的属性为checked的值
bol=bol||true;
}
if(bol)
args.IsValid=true;
else
args.IsValid=false;
  
}
  
</script>

<asp:checkboxlist id="huanjing" runat="server" Height="36px" Width="400px" RepeatDirection="Horizontal">
 <asp:ListItem Value="Win98">Win98</asp:ListItem>
 <asp:ListItem Value="WinMe">WinMe</asp:ListItem>
 <asp:ListItem Value="WinXP">WinXP</asp:ListItem>
 <asp:ListItem Value="Win2000">Win2000</asp:ListItem>
 <asp:ListItem Value="Win2003">Win2003</asp:ListItem>
 <asp:ListItem Value="Unit">Unit</asp:ListItem>
 </asp:checkboxlist><asp:customvalidator id="CustomValidator1" runat="server" 
ErrorMessage="运行环境没有选择,请选择运行环境" ClientValidationFunction="check"></asp:customvalidator

------解决方案--------------------
ClientValidationFunction="checkbranch()" 多了扩号
=> ClientValidationFunction="checkbranch"