ASP:RequiredFieldValidator做回发 [英] ASP:RequiredFieldValidator doing postback

查看:50
本文介绍了ASP:RequiredFieldValidator做回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个文本框的必填字段验证器。





< asp:TextBox runat =serverID =txtUserNameTabIndex =1/>



< asp:RequiredFieldValidator ID =reqUserNamerunat =serverControlToValidate =txtUserNameErrorMessage =用户名字段是必需的。 ValidationGroup =validateSave/>



< asp:Button ID =btnLoginrunat =serverText =LoginOnClick =btnLogin_ClickValidationGroup =validateSave/>



此代码在我的本地计算机和在Windows 7操作系统中运行的开发服务器中正常工作。



但在具有Windows 2008的测试服务器中,当文本框为空并且同时发回时,会显示错误消息。



我试图给出EnableClientScript = true和CausesValidation = true。但没有任何效果。



非常感谢任何快速帮助。



谢谢,

Nithiya

Hi,

I have a Required Field validator for a Text box.


<asp:TextBox runat="server" ID="txtUserName" TabIndex="1" />

<asp:RequiredFieldValidator ID="reqUserName" runat="server" ControlToValidate="txtUserName" ErrorMessage="The user name field is required." ValidationGroup="validateSave"/>

<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" ValidationGroup="validateSave"/>

This code works fine in my local machine and in the development server which is running in Windows 7 OS.

But in the testing server which has Windows 2008, error message is displayed when the textbox is empty and at the same time post back happens.

I tried to give EnableClientScript = true and CausesValidation=true. But nothing works out.

Any quick help is much appreciated.

Thanks,
Nithiya

推荐答案

想不到,为什么postBack Occure。

Can't think about that, why postBack Occure.
but my suggesion is..try<br />
Use a Validation Group and check this group on server side like that..




protected void btnLogin_Click(object sender, EventArgs e)
{
Page.Validate("VGroup");//VGroup is the Validation group
if (!Page.IsValid)
 {
   return;
 }
else
{
//do your Work...

}
}



ref。

https://msdn.microsoft.com /en-us/library/ms227424(v=vs.140).aspx [ ^ ]


这篇关于ASP:RequiredFieldValidator做回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆