locked
AJAX Update Panel in User Control RRS feed

  • Question

  • User1858009984 posted

    Hi,

    I am using ajax update panel in asp.net application and facing the below issue

    In User Control (ascx) having asp.net dropdowns and with its selected item, parent page value should be dynamically change without post back, i have used ajax updatepanel but not working

    Saturday, January 20, 2018 6:21 AM

All replies

  • User-707554951 posted

    Hi Ravindranath M

    Working code as below:

    WebUserControl:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="CaseTest.CaseTest.WebUserControl2" %>
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        <asp:ListItem Value="0">Please select
        </asp:ListItem>
         <asp:ListItem Value="1">1</asp:ListItem>
        <asp:ListItem Value="2">2</asp:ListItem>
    </asp:DropDownList>

    ascx.cs:

     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            {
                ((this.Parent.Page).FindControl("TextBox1") as TextBox).Text = DropDownList1.SelectedItem.Text; ;
            }

    Aspx:

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    
            <uc1:WebUserControl2 runat="server" id="WebUserControl2" />
                </ContentTemplate>
            </asp:UpdatePanel>

    Output:

    Best regards

    Cathy

    Monday, January 22, 2018 9:21 AM