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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate ascx Seperately.

Status
Not open for further replies.

crazyboybert

Programmer
Jun 27, 2001
798
GB
Hi All

I have 2 .ascx controls (say a.ascx and b.ascx) on the same aspx page(say form.aspx). Sometimes one or the other is visible sometimes both. When only one of the controls is visible when i call Page.IsValid from the codebehind form for the control(say a.ascx.cs) it only validates the control a.ascx. However if both the controls are visible then a call of Page.IsValid from the codebehind file of either control (a.ascx.cs or b.ascx.cs) causes validation on the entire webform - form.aspx.

is there anyway to make a user control only validate the fields within it or am i going to have to specifically check the value of each field on the relevant control when both are visible on the page.

Thank in advance for any help

Rob

------------------------------------

On with the dance! let joy be unconfined;
No sleep till morn, when Youth and Pleasure meet
To chase the glowing hours with flying feet.
-Byron

------------------------------------
 
Hmmm. This is a problem that just keeps coming back and I've never found a truly satisfactory solution. Perhaps its a bad design decision to have two user controls on the page and try to use them as seperate forms. That would be too easy a backdoor around the "not allowed two server forms in one page" problem I guess.

Still it would be nice if there was some form of UserControl.IsValid property. I'm thinking it maybe worth just writing a control to do this but then i'm not sure if it would be able to only find and validate the controls from the ascx if the built-in validation doesn't?

Any thoughts welcome. Cheers.

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
Hi LV

Thanks for the link. You have probably seen my other post on this subject and the class I wrote to handle validation within a given control? This class has an IsValid property and a method Validate(). I've been thinking of turning it into a web control, which would seem to naturally want to inherit the IValidator Interface. Not really worked out interfaces yet, I've read a fair bit around the subject but can't quite see the resaon for them yet. Maybe this will be my chance. Thanks again.

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top