469,608 Members | 1,547 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,608 developers. It's quick & easy.

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

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?
Dec 28 '05 #1
3 1528
On Wed, 28 Dec 2005 13:39:03 -0800, dei1c3 wrote:
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.

Dec 28 '05 #2
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...

"dei1c3" wrote:
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?

Dec 29 '05 #3
"Sergey Poberezovskiy" wrote:
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.
Dec 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sundaresan | last post: by
reply views Thread by KB | last post: by
2 posts views Thread by Eric Maia | last post: by
2 posts views Thread by moondaddy | last post: by
reply views Thread by Nariban Barkan | last post: by
reply views Thread by Solution2021 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.