Validation Control in ASP.NET [Resolved]

Posted by .Netlearner under ASP.NET on 8/17/2012 | Points: 10 | Views : 1101 | Status : [Member] | Replies : 3
Hello All,

Am having div block in my aspx page which will get displayed while i click a button as a pop up.My problem is i have required field validators on the div block too so even though i didnt need that popup and other process is unable to continue unless i give values to all the controls in the div block also how can i acheive this.Please guide me.Thanks in advance




Responses

Posted by: Ranjeet_8 on: 8/17/2012 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved
suppose you have four text boxes and two button. when you click the first button it validates the first two text boxes. and when you click the second button it validates the last two text boxes. if you will not use the validation group property when you will click the any button it will validate the all four text boxes and will not proceed untill you have filled all four text boxes rather than two. now when you will use validation group property you will set same validation group for first two text boxes and first button and another validation group for last two text boxes and second button. now when you click either button it will only validate the textboxes which are of the same validation group from which this button belongs.

For Eg :

<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="First"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ValidationGroup="First" ErrorMessage="TextBox1 should not be blank"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server" ValidationGroup="First"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ValidationGroup="First" ErrorMessage="TextBox2 should not be blank"
ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" ValidationGroup="First" Text="Button 1" />
<br />
<br />
<asp:TextBox ID="TextBox3" runat="server" ValidationGroup="Second"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ErrorMessage=" TextBox3 should not be blank"
ControlToValidate="TextBox3" ValidationGroup="Second">
</asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox4" runat="server" ValidationGroup="Second"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ErrorMessage=" TextBox4 should not be blank"
ControlToValidate="TextBox4" ValidationGroup="Second">
</asp:RequiredFieldValidator>
<asp:Button ID="Button2" runat="server" ValidationGroup="Second" Text="Button 2" />


.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 8/17/2012 [Member] Starter | Points: 25

Up
0
Down
I Got the term, Can anyone give some examples and explain what is validation group and how can we apply it

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 8/17/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks a lot

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response