Problem w/ Validation in UserControl with 2 controls on the same p

G

Guest

I've created a WebUserControl which is Composite Control. It includes
several controls including a few RangeValidator controls and a
ValidationSummary control. The WebUserControl works properly in most
situations, but I've discovered a problem when I place 2 or more of these
controls on the same page. Basically, the ValidationSummary control on each
of the WebUserControls seems to be displaying error messages for
RangeValidators on ALL instances of the WebUserControl on the page, not just
the one it is actually part of!

For testing and discussion purposes, I've created a simpler version o fthe
WebUserControl (i'll call it TestControl) that consists of:
1 TextBox
1 RangeValidator
1 ValidationSummary

I've set the RangeValidator to validate the TextBox for a range of Integers
between 0 and 9. So any single digit will be valid, any double digit (or
more) won't be.

I've then created a Default.aspx page and added the following controls to it:
2 TestControls
1 Button

I then build and browse to the page. And I find the following:

- If I enter a valid number in the TextBox of 1 TestControl and an invalid
number in the TextBox of the other TestControl and click the button, the
ValidationSummary of BOTH TestControls will display the RangeValidator's
error message ONCE.

- If I enter invalid numbers in the TextBoxes of both TestControls and click
the button, the ValidationSummary of BOTH TestControls will display the
RangeValidator's error message TWICE (presumably, once for each TextBox that
is not valid).

I've looked through the client-side script that is generated for the page
and it SEEMS to be ok. The controls on each TestControl are differentiated
in name/ID (i.e. TestControl1_RangeValidator vs TestControl2_RangeValidator,
etc...). Additionally, the problem still occurs if I turn off client-side
validation.

Note: I am using ASP.NET 2.0, but I don't know if this problem is specific
to that version of the framework or not.

Any thoughts?
 
I

intrader

I've created a WebUserControl which is Composite Control. It includes
several controls including a few RangeValidator controls and a
ValidationSummary control. The WebUserControl works properly in most
situations, but I've discovered a problem when I place 2 or more of these
controls on the same page. Basically, the ValidationSummary control on each
of the WebUserControls seems to be displaying error messages for
RangeValidators on ALL instances of the WebUserControl on the page, not just
the one it is actually part of!

For testing and discussion purposes, I've created a simpler version o fthe
WebUserControl (i'll call it TestControl) that consists of:
1 TextBox
1 RangeValidator
1 ValidationSummary

I've set the RangeValidator to validate the TextBox for a range of Integers
between 0 and 9. So any single digit will be valid, any double digit (or
more) won't be.

I've then created a Default.aspx page and added the following controls to it:
2 TestControls
1 Button

I then build and browse to the page. And I find the following:

- If I enter a valid number in the TextBox of 1 TestControl and an invalid
number in the TextBox of the other TestControl and click the button, the
ValidationSummary of BOTH TestControls will display the RangeValidator's
error message ONCE.

- If I enter invalid numbers in the TextBoxes of both TestControls and click
the button, the ValidationSummary of BOTH TestControls will display the
RangeValidator's error message TWICE (presumably, once for each TextBox that
is not valid).

I've looked through the client-side script that is generated for the page
and it SEEMS to be ok. The controls on each TestControl are differentiated
in name/ID (i.e. TestControl1_RangeValidator vs TestControl2_RangeValidator,
etc...). Additionally, the problem still occurs if I turn off client-side
validation.

Note: I am using ASP.NET 2.0, but I don't know if this problem is specific
to that version of the framework or not.

Any thoughts?
Please include your test case.
Of the top of my head, the problem has to do with ids of the composite
controls; they should have their own namespace.
 
G

Guest

I am not sure whether it's changed in 2.0, but if you look into
WebUIValidation.js script that Microsoft used in 1.1, every ValidationSummary
control will loop through ALL enabled validators on the page - not sure how
to resolve your problem though - if you try to describe what is it that you
are trying to achieve - I may be able to suggest a work around...
 
G

Guest

Sergey Poberezovskiy said:
I am not sure whether it's changed in 2.0, but if you look into
WebUIValidation.js script that Microsoft used in 1.1, every ValidationSummary
control will loop through ALL enabled validators on the page - not sure how
to resolve your problem though - if you try to describe what is it that you
are trying to achieve - I may be able to suggest a work around...

Yes...that's what I figured out after I posted. My assumption was that the
summary would be specific to the WebUserControl, but it encompasses the
entire page.

My work around was to remove the summary and layout the actual validators to
create a summary which worked fine.

Thanks anyway.
 
Joined
Aug 26, 2009
Messages
1
Reaction score
0
Solution

I ran into a similar problem. I was able to resolve it by setting the validationgroup to the same value for all the involved controls (and the submit button).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top