当我在asp.net表单上添加服务器控件的验证时,链接按钮的onclick事件没有触发 [英] link button's onclick event not firing when I added validation for server controls on asp.net form
本文介绍了当我在asp.net表单上添加服务器控件的验证时,链接按钮的onclick事件没有触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
form.aspx
< asp:LinkButton ID =lnkLogoutrunat =serveronclick =lnkLogout_Click>退出
< asp:TextBox ID =txtEmailrunat =server>
< asp:RegularExpressionValidator ID =regexEmailValidrunat =serverValidationExpression =\ w +([ - +。] \ w +)* @ \ w +([ - 。] \ w +)* \.\ + +([ - 。] \ w +)*ControlToValidate =txtEmailErrorMessage =无效的电子邮件格式>< / asp:RegularExpressionValidator>
form.aspx.cs
protected void lnkLogout_Click(object sender,EventArgs e)
{
FormsAuthentication.SignOut();
Session.Abandon();
Response.Redirect(〜/ Login.aspx);
}
解决方案
将链接的CausesValidation属性更改为按钮真正的。
form.aspx
<asp:LinkButton ID="lnkLogout" runat="server" onclick="lnkLogout_Click">Log out <asp:TextBox ID="txtEmail" runat="server"> <asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="txtEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
form.aspx.cs
protected void lnkLogout_Click(object sender, EventArgs e) { FormsAuthentication.SignOut(); Session.Abandon(); Response.Redirect("~/Login.aspx"); }
解决方案
Change the "CausesValidation" property of your link to button to "True".
这篇关于当我在asp.net表单上添加服务器控件的验证时,链接按钮的onclick事件没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文