A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Group validation in ASP.NET 2.0This tutorial will teach you how to use the ValidationGroup property introduced in ASP.NET 2.0, which allows you to link validators to buttons, so that certain buttons in a form can only trigger certain validators. |
On Wednesday, July 27th 2005 at 01:32 PM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 4.5 with 30 votes) |
||
|
Validation groups represent something new, introduced in ASP.NET 2.0. With this feature you can implement validation on groups of controls. Before ASP.NET 2.0, when submitting a form, all the controls on the page were being validated. So when you press the Submit button, each and every TextBox or other control that has a validator, was checked. However, this caused a problem when you had multiple forms on a page, with two or more submit buttons. Pressing one of the buttons would start to validate all the controls on a page, and that's not what we wanted. So let's see how these validation groups work. Start a new Web Site in Visual Studio 2005: ![]() Add two panels to the form and some TextBoxes in both. For each TextBox add a validator, I added RequiredFieldValidators because they are the most common ones. Also, add a button in each of the panel, so that our WebForm looks something like: ![]() Be sure to set each validator to validate one of the TextBoxes. You can do this by setting the ControlToValidate property in the Properties window. After each TextBox has its RequiredFieldValidator, compile and run the web application. Type something into the TextBoxes in Panel2 and leave the TextBoxes in Panel1 blank, because we are not interested in that form. Press the submit button (the second one, of course), and watch the result: ![]() Bummer! Even though we pressed the second button, the validators in the first form reacted and the form didn't get submitted. Here's where the validation groups come in handy. Click the first button and in the Properties window scroll to the ValidationGroup property and give it a name, Form1: Now do the same thing for the second button, set the ValidationGroup property to Form2. We're not done yet. The RequiredFieldValidators also have a ValidationGroup property, we need to set this property of the RequiredFieldValidators from Panel1 to the same name we gave the submit button in Panel1: Form1. Same thing needs to be done for the validators in Panel2, set their ValidationGroup property to the same name as the second button: Form2. This way each button is linked to the validators it should fire when it is pressed. You can compile and run the web application now. ![]() As you can see in the screenshot above, clicking the first button will now fire only the validators that are grouped with that button. |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current Commentsb
Can i use one RequiredFieldValidators for 2 text box's
A Requiredfieldvalidator always validates 1 control (1 textbox in the example). You can not validate 2 textboxes with 1 validator. In our e-marketing web application myMailmarket(http://www.mymailmarket.be) we used a lot of validators, to restrict input of the users!
Hi,
i am using lot of controls in registration form.all validations r check in one button.how can put group for only two fields..
ex.select industry..if i select otherindustry..than other text box is visible..at that time i need check other text box is empty or not
awesome artical .
helps a lot thanks.
hi this is useful to me. is anyone can clear about postback property to me well. a
This was great, very well explained. Thanks!
Can one control belong to two different validation groups?
wew
How can i use the same validations for more buttons, should i make more validation groups again, or the same one?
Hi!
This was good. But I want to learn code-behind it. e.g if for password, I want to give validation i.e minimum character length should be 8 and if length is less than 8 character Error Message should get display in browser. Then What is the codebehind for such type of validation?
Hi!
This was good. But I want to learn code-behind it. e.g if for password, I want to give validation i.e minimum character length should be 8 and if length is less than 8 character Error Message should get display in browser. Then What is the codebehind for such type of validation?
Salam,,Thanks for this information,,your site is helping me alot, thnks again..
Hello. What about if you add a validationSummary on your page. Suppose you add a validationSummary for your group1. If you enter incorrect values in group1 you'll see the summary. Next, you add correct values to group2. Result: summary is disapear. How to avoid this? Thx
Great example, I was wondering if this could be done with using just 1 button on the page and having a radio button for the user to select the group before submitting.
It was very nice and easy to follow.
I have lot of textboxes and drop downs in my page.
I also have a grid view which has got one drop down and 5 textboxes which are editable. How can i give validations for these controls in the grid view? If any one of them is missing, then i should display an error message. Can anyone plz help me?
Thanks in advance
Mahesh
Hey guys. I have this tiny bit problem stuck here. See, I have finished my RSS feed, tested it and all works perfectly, but when I remove an article from my feed it still showed in the reader. How do i get the reader to see the article is no longer part of the feed. Any ideas what's wrong?
http://www.rsschannelwriter.com/
Hey guys. I have this tiny bit problem stuck here. See, I have finished my RSS feed, tested it and all works perfectly, but when I remove an article from my feed it still showed in the reader. How do i get the reader to see the article is no longer part of the feed. Any ideas what's wrong?
http://www.rsschannelwriter.com/
Hey guys. I have this tiny bit problem stuck here. See, I have finished my RSS feed, tested it and all works perfectly, but when I remove an article from my feed it still showed in the reader. How do i get the reader to see the article is no longer part of the feed. Any ideas what's wrong?
http://www.rsschannelwriter.com/
Hey guys. I have this tiny bit problem stuck here. See, I have finished my RSS feed, tested it and all works perfectly, but when I remove an article from my feed it still showed in the reader. How do i get the reader to see the article is no longer part of the feed. Any ideas what's wrong?
http://www.rsschannelwriter.com/
How to use validation property in Grid view?
Related Tutorials
Related Source Code
ASP.NET Job Search