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. Advertisements

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:
    608
    bruce barker
    Jul 18, 2003
  2. D. Shane Fowlkes
    Replies:
    2
    Views:
    6,182
    Martin Dechev
    Feb 23, 2004
  3. Roni Burd
    Replies:
    6
    Views:
    2,750
    Roni Burd
    Jul 3, 2004
  4. Marcio Kleemann

    RequiredFieldValidator not working

    Marcio Kleemann, Aug 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,748
    Marcio Kleemann
    Aug 12, 2004
  5. Brian
    Replies:
    1
    Views:
    1,909
    Brian
    Apr 22, 2005
  6. puzzlecracker
    Replies:
    1
    Views:
    705
    James Kanze
    Aug 7, 2008
  7. James
    Replies:
    2
    Views:
    268
    Teemu Keiski
    Dec 4, 2005
  8. Roni Burd
    Replies:
    4
    Views:
    325
    Roni Burd
    Jul 3, 2004
Loading...