We help IT Professionals succeed at work.

2 user controls on one page

Camillia
Camillia asked
on
I will simplify this.

1. I have 2 user controls. They each have one field. For example, last name and phone number
2. Last name and phone are both user controls is required
3. I have a requiredfieldvalidtor in each user control for the lastname textbox and phone textbox
4. Both user controls have a submit button
5. I place both user controls on a page. One top of the page, the other one below it.
Now

Since both fields are required and I have required field validator on both fields...I enter something in Phone textbox BUT nothing in lastname (because this is on UC1). I click sumbit but the fieldvalidator in UC1 gets activated (the one for last name).

I need the validators to only work for that specific user control. How can I do this?

Comment
Watch Question

GlobaLevelProgrammer

Commented:
Since both fields are required and I have required field validator on both fields...I enter something in Phone textbox BUT nothing in lastname (because this is on UC1). I click sumbit but the fieldvalidator in UC1 gets activated (the one for last name).



>>>Im sorry I read this a few times and I still dont get whats going on...from what I read the filedvator should be activated...and UC1 is just the tag that you registered at the top of the page...
CERTIFIED EXPERT

Author

Commented:
sorry, bad english :)

I have 2 user controls: UC1 and UC2. Both are on xxx.aspx page.
UC1 has a required filed phone
UC2 has a required field last name
Both UC1 and UC2 have a submit button.

I enter something in phone. Nothing in last name. I click submit button in UC1. At this point, submit should should work. It should NOT validate last name since last-name is on user contorl 2 (UC2). But it does validate last-name....

They are 2 separate user controls with 2 separate buttons so validation should occur within their own "space"...UC1 button should NOT validate UC2's fields .
GlobaLevelProgrammer

Commented:
okay so I guess we are getting crossover...then you can you check 2 things...one that required fieled validator in the .ascx page and see that uc1 and uc2 arent sharing the same thing...check any .aspx or .ashx page that the user control may call in the process...
CERTIFIED EXPERT

Author

Commented:
so, there shouldnt be any cross over ... i mean...this is NOT nomal behavior? I thought maybe this is how user contols work and i need to code something in code behind instead of using required field validators
Programmer
Commented:
yes, that is what I would do..is get rid of the of the RFV and use code in code behind..and puts flags on them..that way you can customize ....per control...


WUC are just custom controls that we can use across pages so we dont have to recode...code in the methods allows you to control data flow...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.