Refreshing an asp.net page from a control in another control

13,158

Solution 1

If you want to reload the entire page (and not just the content of the UpdatePanels) you can do:

Page.Response.Redirect("mypagename.aspx");

Solution 2

Assuming you don't have a control over the parent user control, you could find the control by searching through the child controls of the parent user control (FindControl). Then once you have the reference to it you could add an event handler:

btnAddButton.OnClick += new EventHandler(MethodThatRefreshesPage);

Since you're in update panels, you would need to do something like Response.Redirect(Request.RawUrl) to refresh the entire page.

Of course, if you do have control over the parent user control, you create your own "AddClicked" event and pass the subscriptions down to the link button..or you could just expose the LinkButton itself as a public property on the user control.

Share:
13,158
user204588
Author by

user204588

Updated on June 25, 2022

Comments

  • user204588
    user204588 almost 2 years

    I want to refresh my asp.net page after someone clicks an "Add" button. However, the "Add" button is part of user control inside another user control and the child control and parent control are both wrapped in Update Panels: Code below is cut short for display, there's a reason the user control is inside another user control

    Inside first control:

    <ajax:UpdatePanel ID="Panel1" runat="server" UpdateMode="Always">
       <ContentTemplate>
                 <uc:Control2 ID="Custom2" runat="server" />
       </ContentTemplate>
    </ajax:UpdatePanel>
    

    Then inside control2

    <ajax:UpdatePanel ID="Panel2" runat="server" UpdateMode="Always">
       <ContentTemplate>
                 <asp:LinkButton ID="AddButton" runat="server" OnClick="AddButton_Click"</asp:LinkButton>
       </ContentTemplate>
    </ajax:UpdatePanel>