Results 1 to 2 of 2

Thread: User controls and validation

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203

    User controls and validation

    I have a User Control that contains a dropdown list and a Required field validator. The dropdown list is a list of states. On my web form, I have 2 instances of this user control. My problem is with the Validator. One instance of the control on the web form requires that the user choose a state from the dropdown list, but the other does not. If either one of the 2 instances is left blank, the Required Field validator shows the * text beside both of them. Is there a way to set a property or something in the user control from the Web form to indicate whether the field is required or not for that particular instance and if so whether to enable the validator control or not?

    The way it works now is confusing to the user because an * appears next to a field that is not required because a different required field was left blank.

    I would like to avoid creating two user controls if possible.

    Please help!

    Thanks.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203

    User Controls and validation [RESOLVED]

    I found the solution to my problem and thought I would post it.

    In my User Control, I put a public property called "Required" and on the page prerender of the control, I checked whether this property was true or false and enabled or disabled the RequiredFieldValidator accordingly.

    On the web form in which I have placed the multiple instances of the control, I set the required property for each instance on the Page Prerender event.

    This solved the problem.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width