0
樣品做工精細採取客戶端,但在後面的代碼,他不檢查頁面驗證樣品返回false即使我禁用驗證他只設置
protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('PostBack occured.');", true);
}
當我更新的代碼背後來驗證的頁面一樣,
protected void Button1_Click(object sender, EventArgs e)
{
Page.Validate("Group1");
if (Page.IsValid)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('PostBack occured.');", true);
}
}
的Page.IsValid始終處於Java腳本在下面的返回false,即使我禁用了驗證的的RequiredFieldValidator與ID = 「ValName的」 爲:
<form id="form1" runat="server">
<u>JavaScript</u>
<hr />
UserName:
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="valName" ControlToValidate="txtName" runat="server"
ErrorMessage="*Required" ForeColor="Red" ValidationGroup="Group1" />
<br />
Enable Validation:
<input type="checkbox" id="CheckBox1" onclick="ToggleValidator(this);" checked="checked" />
<br />
<asp:Button Text="Submit" runat="server" OnClick="Button1_Click" ValidationGroup="Group1" />
<script type="text/javascript">
function ToggleValidator(chk) {
var valName = document.getElementById("<%=valName.ClientID%>");
ValidatorEnable(valName, chk.checked);
}
</script>
<br />
<br />
</form>
請針對此問題的任何幫助