Question

Inside form view I have drop down list on selected index change I have text box appearing. Now I want to keep both these drop down and Text box inside Ajax update panel. Upon click button out side update panel I want to save these two fields as well.

Any help Much appreciated.

Here aspx code

<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                    <br />
                    <asp:DropDownList ID="ddlLName"
                        runat="server" ValidationGroup="VG1" SelectedValue='<%# Bind("LNAMEIFYES") %>' OnSelectedIndexChanged="ddlLName_SelectedIndexChanged" AutoPostBack="True">
                        <asp:ListItem Value="">Please select...</asp:ListItem>
                        <asp:ListItem Value="1">Yes</asp:ListItem>
                        <asp:ListItem Value="2">No</asp:ListItem>

                    </asp:DropDownList>
                    <br />
                    <asp:Panel ID="pnlLNAme" runat="server" Visible="false">
                        LName:
                     <asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' />
                        <br />
                    </asp:Panel>

Code Behind

protected void ddlLName_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddlLName = (DropDownList)FormView1.FindControl("ddlLName");
        if (ddlLName.SelectedValue == "1")
        {
            Panel pnlLNAme = (Panel)FormView1.FindControl("pnlLNAme");
            pnlLNAme.Visible = true;

        }
        else
        {
            Panel pnlLNAme = (Panel)FormView1.FindControl("pnlLNAme");
            pnlLNAme.Visible = false;

        }
    }
Was it helpful?

Solution

I solved the problem by using by using two update panals, using trigger in one of the update panal.

<EditItemTemplate>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        ID:
            <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
                        <br />
                        Name:
            <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                        <br />
                        <asp:DropDownList ID="ddlLName"
                            runat="server" ValidationGroup="VG1" SelectedValue='<%# Bind("LNAMEIFYES") %>' OnSelectedIndexChanged="ddlLName_SelectedIndexChanged" AutoPostBack="True">
                            <asp:ListItem Value="">Please select...</asp:ListItem>
                            <asp:ListItem Value="1">Yes</asp:ListItem>
                            <asp:ListItem Value="2">No</asp:ListItem>

                        </asp:DropDownList>
                        <br />
                        <asp:Panel ID="pnlLNAme" runat="server" Visible="false">
                            LName:
                 <asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' />
                            <br />
                        </asp:Panel>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        Salary:
            <asp:TextBox ID="SalaryTextBox" runat="server" Text='<%# Bind("Salary") %>' />
                        <br />
                        IsActive:
            <asp:CheckBox ID="IsActiveCheckBox" runat="server" Checked='<%# Bind("IsActive") %>' />
                        <br />
                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                        &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click_Enent" />
                    </Triggers>
                </asp:UpdatePanel>
            </EditItemTemplate>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top