Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted

1 solution

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..

C#
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[^]
 
Share this answer
 
v2
Comments
Nithiya kiruthiga 6-Feb-15 8:49am    
But it is working in a server without this code. Why is it different in another server? Any idea?
/\jmot 6-Feb-15 15:48pm    
i don't know, sometime it happens,can't understand. and i didn't find any solution and i just used above code for the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900