RequiredFieldValidator not working for dependent dropdown

Discussion in 'ASP .Net' started by xbound, May 13, 2010.

  1. xbound

    xbound Guest

    I have two dropdowns: I've added a first item like "Please Select" to each
    and each has it own RequiredFieldValidator control which fires if the user
    does not select something. The code for the second one looks like this

    <asp:DropDownList ID="ddl2" runat="server" AutoPostBack="true"
    AppendDataBoundItems="true" ......
    OnSelectedIndexChanged="ddl2_SelectedIndexChanged">
    <asp:ListItem Text="Please select" Value="0" />
    </asp:DropDownList>
    <asp:RequiredFieldValidator ID="reqddl2" runat="server"
    ControlToValidate="ddl2"
    Display="Dynamic" ErrorMessage="Name is required"
    InitialValue="0">&larr;Required</asp:RequiredFieldValidator>


    The second dropdown is populated depending on what's selected in the first
    one. In the SelectedIndexChanged event of the first dropdown I've added
    this statement [ ddl2.Items.Insert(0, "Please Select") ] because otherwise
    that first item won't show up in the second dropdown anymore once the value
    in the first dropdown has changed. The problem is that afterward the
    validation control for the second dropdown no longer works.

    So do I need to validate the second dropdown manually? Any insight
    appreciated.
    xbound, May 13, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob
    Replies:
    4
    Views:
    486
    bruce barker
    Jul 18, 2003
  2. D. Shane Fowlkes
    Replies:
    2
    Views:
    5,901
    Martin Dechev
    Feb 23, 2004
  3. Roni Burd
    Replies:
    6
    Views:
    2,380
    Roni Burd
    Jul 3, 2004
  4. puzzlecracker
    Replies:
    1
    Views:
    503
    James Kanze
    Aug 7, 2008
  5. Rudi
    Replies:
    0
    Views:
    599
Loading...

Share This Page