Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegularExpressionValidator inside usercontrol

Status
Not open for further replies.

ecannizzo

Programmer
Sep 19, 2000
213
US
I have a regularexpressionvalidator attached to a textbox in a usercontrol. I add the usercontrol dynamically to my page. It works fine.

However, if I add the usercontrol multiple times to my page (so let's say my page has the usercontrol on it 4 times) then when the regularexpressionvalidator in one of the usercontrols is triggered it gives me the message 4 times (since that's how many times the usercontrol is on the page) even though I'm just messing with one of the usercontrol.

Does anyone know how to fix this?
 
how many of the validators are valid? when you validate the page all 4 validators are evaluated. to selectively validate the controls you need to associate the validator and firing control (button usually) with a validation group.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
When you add the usercontrol to the page, are you assigning a uniqueid to each of them?
 
the unique id's are different'. Also, I do have a validationgroup set on the submit button. But all the validators and validationgroups have the same name on each usercontrol (they are set in the html). Could that be the problem? What is the best way to fix that?
 
yes, you need to set the validation group for each user control independently. the best way to do this is to expose a public set method on the user control and set the validation group accordingly. example
Code:
for(int i=0;i<10;1++)
{
   MyControl ctrl = (MyControl)Page.LoadControl("path to control");
   ctrl.UseValidationGroup("vg_" + i);
}
then you would need to set your control which fires the events accordingly.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top