Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

post back of Dropdownlist in web user control all other fields become empty

i have a aspx page in which i have placeholder inside the panel

as

<div>
    <div>
        <div>
            <div>
                <div>
                    <div>
                        <asp:UpdatePanel runat="server" ID="UpdatePanelLinks">
                            <ContentTemplate>
                                <center>
                                    <asp:Button Text="ADD" ID="btnAdd" runat="server" Width="100" OnClick="btnAdd_Click" />&nbsp;
                                    <asp:Button Text="Edit" ID="btnEdit" runat="server" Width="100" OnClick="btnEdit_Click" />&nbsp;
                                    <asp:Button Text="Delete" ID="btnDelete" runat="server" Width="100" OnClick="btnDelete_Click" /></center>
                                <asp:LinkButton ID="usercontroldata" runat="server" Text="Branches" 
                                    OnClick="usercontrol_Click"></asp:LinkButton>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </div>
                </div>
                <div >
                    <asp:LinkButton ID="lnkDepartments" runat="server" Text="Departments" OnClick="lnkDepartments_Click"></asp:LinkButton>
                </div>
                <div >
                </div>
                <div >
                    <asp:LinkButton ID="lnkProjects" runat="server" Text="Projects" OnClick="lnkProjects_Click"></asp:LinkButton>
                </div>
                <div >
                </div>
                <div >
                    &nbsp;
                </div>                       
            </div>
            <div>
                <div>
                    <asp:Label Text="" Visible="false" ID="lblmessage" runat="server" />
                    <div>
                        <asp:UpdatePanel ID="UpdatePanel" runat="server">
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="lnkBranches" EventName="Click" />
                                <asp:AsyncPostBackTrigger ControlID="lnkDepartments" />
                                <asp:AsyncPostBackTrigger ControlID="lnkProjects" />
                                <asp:AsyncPostBackTrigger ControlID="btnAdd" />
                                <asp:AsyncPostBackTrigger ControlID="btnEdit" />
                                <asp:AsyncPostBackTrigger ControlID="btnDelete" />
                            </Triggers>
                            <ContentTemplate>
                                <asp:Panel runat="server" ID="MainPanel">
                                    <div class="padding_branch">
                                        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                                    </div>
                                </asp:Panel>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="lnkBranches" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="lnkDepartments" />
        <asp:AsyncPostBackTrigger ControlID="lnkProjects" />
        <asp:AsyncPostBackTrigger ControlID="btnAdd" />
        <asp:AsyncPostBackTrigger ControlID="btnEdit" />
        <asp:AsyncPostBackTrigger ControlID="btnDelete" />
    </Triggers>
    <ContentTemplate>
        <asp:Panel runat="server" ID="MainPanel">
            <div >
                <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>                                     
            </div>
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>    

and on the aspx.cs page i am dynamically add the web user control on click of links

and on the add button click the new user control is loaded

 protected void usercontrol_Click(object sender, EventArgs e)
 {
        if (ViewState["controlname"] != null)
        {
            PlaceHolder pl = MainPanel.FindControl(ViewState["controlname"].ToString()) as PlaceHolder;
            if (pl.Controls.Count > 0)
            {
                pl.Controls.RemoveAt(0);
            }
        }

        Control uc = (Control)Page.LoadControl("~/usercontrol_Data.ascx");

        ViewState["path"] = "~/usercontrol_Data.ascx";
        ViewState["controlname"] = "PlaceHolder1";
        ViewState["name"] = "usercontrol";
        PlaceHolder1.Controls.Add(uc);
 }

i am also mainaining the web user control on Page_Load

        if (Page.IsPostBack)
        {
            if (ViewState["path"] != null)
            {
                Control uc1 = (Control)Page.LoadControl(ViewState["path"].ToString());

                PlaceHolder pl = MainPanel.FindControl(ViewState["controlname"].ToString()) as PlaceHolder;
                pl.Controls.Add(uc1);
            }
        }

and there is dropdown list on the form user control when iam selecting any of the option from the user control it post back and all the other fields become empty for textboxes etc . this happans for the first time and for next time all the fields retain there values

please help

thanks

like image 298
G.S Bhangal Avatar asked Dec 07 '25 20:12

G.S Bhangal


1 Answers

i have done this by assigning the same ID to the control every time when the control loads dynamically. this is because when the control added dynamically every time it get the new ID that is creating the problem for me

uc1.ID="Web_User_Control_ID";

every time the control load asign this ID to it will resole the problem

like image 78
G.S Bhangal Avatar answered Dec 09 '25 09:12

G.S Bhangal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!