返回首页

Hello,

 

I have 3 dropdown list. All 3 are required field validators.

 

On Selected index change of country, state dropdown is going to fill and on selected index change of state, city dropdown is going to fill.

 

Now, the issue is, when i click on register button click, without filling any details in form, all validations are coming properly.

 

Now,when i select country, the validation message of country disappers. that part is working perfectly.

 

But when i select any state, the validation message is not going to disapper.

 

For that, i have removed eventname from asynctrigger of update panel. Now, validation message for state is going to disapper, but city field is not going to bind because we removed trigger event.

 

My requirement is if someone select country, then country validation message should disapper. State and city validation message should be there. If i select state, then state validation message should disappear, city validation message should be available.

 

I am sending my code as below,

 

                       <div class="time_lne">

                                <label>

                                    <span>

                                        <img src="images/red_error.png" alt="error" /></span> Country</label>

                                <asp:UpdatePanel ID="uppnlCountry" runat="server">

                                    <ContentTemplate>

                                        <asp:DropDownList ID="ddlCountry" CssClass="select_ex" Width="304px" AutoPostBack="true"

                                            runat="server" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">

                                        </asp:DropDownList>

                                    </ContentTemplate>

                                </asp:UpdatePanel>

                                <span>

                                    <asp:RequiredFieldValidator ID="reqCountry" runat="server" ErrorMessage="This Field is required"

                                        ForeColor="Red" ControlToValidate="ddlCountry"></asp:RequiredFieldValidator>

                                </span>

                            </div>

                            <div class="time_lne">

                                <label>

                                    <span>

                                        <img src="images/red_error.png" alt="error" /></span> Province</label>

                                <asp:UpdatePanel ID="uppnlState" runat="server" UpdateMode="Conditional">

                                    <ContentTemplate>

                                        <asp:DropDownList ID="ddlState" CssClass="select_ex" Width="304px" AutoPostBack="true"

                                            runat="server" OnSelectedIndexChanged="ddlState_SelectedIndexChanged">

                                        </asp:DropDownList>

                                    </ContentTemplate>

                                    <Triggers>

                                        <asp:AsyncPostBackTrigger ControlID="ddlCountry" EventName="SelectedIndexChanged" />

                                    </Triggers>

                                </asp:UpdatePanel>

                                <span>

                                    <asp:RequiredFieldValidator ID="reqState" runat="server" ErrorMessage="This Field is required"

                                        ForeColor="Red" ControlToValidate="ddlState"></asp:RequiredFieldValidator>

                                </span>

                            </div>

                            <div class="time_lne">

                                <asp:UpdatePanel ID="uppnlCity" runat="server" UpdateMode="Conditional">

                                    <ContentTemplate>

                                        <div class="time_lne">

                                            <label>

                                                <span>

                                                    <img src="images/red_error.png" alt="error" /></span> City</label>

                                            <asp:DropDownList ID="ddlCity" CssClass="select_ex" Width="304px" AutoPostBack="true"

                                                runat="server" OnSelectedIndexChanged="ddlCity_SelectedIndexChanged">

                                            </asp:DropDownList>

                                        </div>

                                    </ContentTemplate>

                                    <Triggers>

                                        <asp:AsyncPostBackTrigger ControlID="ddlState" EventName="SelectedIndexChanged" />

                                    </Triggers>

                                </asp:UpdatePanel>

                                <span>

                                    <asp:RequiredFieldValidator ID="reqCity" runat="server" ErrorMessage="This Field is required"

                                        ForeColor="Red" ControlToValidate="ddlCity"></asp:RequiredFieldValidator>

                                </span>

                            </div>

 

In .cs file i have done this code

 

 protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)

    {

        BindState();

 

    }

 

    /// <summary>

    /// Used to bind city drop down as per the state drop down selection changes

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)

    {

        BindCity();

 

    }

 

    /// <summary>

    /// Used to bind suburb drop down as per the city drop down selection changes

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)

    {

        BindSuburb();

    }

 



=========

 

 /// <summary>

    /// Used to bind state drop down

    /// </summary>

    private void BindState()

    {

        try

        {

            string strCountryId = ddlCountry.SelectedValue;

            ddlState.Items.Clear();

            if (strCountryId != "")

            {

                StateBL state = new StateBL();

                ddlState.DataSource = state.GetStateByCountry(Convert.ToInt16(strCountryId));

                ddlState.DataTextField = "StateName";

                ddlState.DataValueField = "Id";

                ddlState.DataBind();

            }

            ddlState.Items.Insert(0, new ListItem("Select State", ""));

        }

        catch (Exception ex)

        {

            ValidationScript("EmployerRegister-->
:4345489 |会员

回答

评论会员: 时间:2