Dropdown list does post back to the server even if you have specified the RequiredFieldValidator

Setting CausesValidation="true" sorts the issue

However do remember 1 thing, Set your validation group property to in order to prevent other validation to be fired.

 

         <div>
                <asp:DropDownList ID="A" AutoPostBack="true" CausesValidation="true" runat="server">
                    <asp:ListItem Text="Select…" Value="-1" />
                    <asp:ListItem Text="1001" Value="1001" />
                    <asp:ListItem Text="1002" Value="1002" />
                </asp:DropDownList>
                <asp:DropDownList ID="B" AutoPostBack="true" CausesValidation="true" runat="server">
                    <asp:ListItem Text="Select…" Value="-1" />
                    <asp:ListItem Text="1001" Value="1001" />
                    <asp:ListItem Text="1002" Value="1002" />
                </asp:DropDownList>
                <asp:DropDownList ID="C" AutoPostBack="true" runat="server">
                    <asp:ListItem Text="Select…" Value="-1" />
                    <asp:ListItem Text="1001" Value="1001" />
                    <asp:ListItem Text="1002" Value="1002" />
                </asp:DropDownList>
            </div>
            <div>
                <asp:RequiredFieldValidator ID="ARequired" InitialValue="-1" ControlToValidate="A" Text="A*" runat="server" />
            </div>
            <div>
                <asp:RequiredFieldValidator ID="BRequired" InitialValue="-1" ControlToValidate="B" Text="B*" runat="server" />
            </div>

 

 

In the above example 1st and 2nd dropdown will not cause postback if you have selected the 1st value. However the third will do post back to the server.

As i mentioned above you must set your validationgroup as needed to prevent other validation to be fired.

Tarun Juneja

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s