Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 461
user204588 Avatar asked Jan 26 '10 19:01

user204588


2 Answers

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

Page.Response.Redirect("mypagename.aspx");
like image 78
Keltex Avatar answered Oct 12 '22 12:10

Keltex


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.

like image 37
WayneC Avatar answered Oct 12 '22 10:10

WayneC