紧急事件:我的验证控件失效了,如下:
Code
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
Display="None" ControlToValidate="TextBox1"></asp:RequiredFieldValidator><ajaxToolkit:ValidatorCalloutExtender
runat="server" TargetControlID="RequiredFieldValidator1">
</ajaxToolkit:ValidatorCalloutExtender>
<asp:Button ID="Button1" runat="server" Text="Button"/>
</div>
</form>
</body>
点击Button会引发验证控件对TextBox的验证,当TextBox为空时,不能提交页面,没有任何的问题。但我做如下修改,将Button的Enable属性置为false,然后在触发某一事件后,Button的Enable属性为true,这时验证控件就会失去作用,代码如下:
Code
<script language="javascript" type="text/javascript">
function pageLoad()
{
$get("TextBox2").onchange=textboxOnchange;
}
function textboxOnchange()
{
$get("Button1").disabled="";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
Display="None" ControlToValidate="TextBox1"></asp:RequiredFieldValidator><ajaxToolkit:ValidatorCalloutExtender
runat="server" TargetControlID="RequiredFieldValidator1">
</ajaxToolkit:ValidatorCalloutExtender>
<asp:Button ID="Button1" runat="server" Text="Button" Enabled="false" />
</div>
</form>
</body>
这是为什么呢?我分析了这两种情况Button在客户对生成的代码:
第一种情况:<input type="submit" name="Button1" value="Button" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("Button1", "", true, "", "", false, false))" id="Button1" />
第二种情况: <input type="submit" name="Button1" value="Button" id="Button1" disabled="disabled" />
第二种情况真的没有生成验证代码,我发现只要在服务器端规定Button的Enable属性,验证控件就会失效,在客户端就规定就不会存在这个问题。
能否解决这个问题,是验证控件一直起作用,望各位高手指导,我这里先谢谢了。