Calling parent page code behind a method from child page code behind - ASP.NET 2.0 Page Inheritance Model

What would be the best way to call the method in the code for the parent page from the code behind the child page in the ASP.NET 2.0 website model?

Scenario: A user clicks a link on the parent page to view a detailed record of the data on the child page (the parent and child elements are separate tow pages). The user will modify the data on the client page. After the child page has processed the update, the child page will close and I need to reinstall the parent page to reflect the update.

I did something similar, but it called the parent page from a user control that was included in the parent page

if(Page.GetType().ToString().Contains("ASP.Default_aspx")) { MethodInfo MyMethod = this.Parent.TemplateControl.GetType().GetMethod("MyMethod"); MyMethod.Invoke(this.Page, null); MyMethod = null; } 

UPDATE: I have to do this from code, because the child page closes after updating the data.

0
source share
3 answers

The easiest way is to do it all on one page using a multivisor or something similar.

Other then with javascript you can call

 document.opener.location.href = "url"; 

to change the url on the parent page. You could just save it in the same order or paste it into the query string and skip these values ​​in Page_Load

+1
source

If you open the child page in a modal pop-up window, you can access window.returnValue on the parent page (via JavaScript), and then cause the page to refresh or call Ajaxy again.

Check this page for how to return a value from a modal popup and do something based on that value on the parent page.

However, if you have the option, I would have avoided opening the editing form on a separate page. I would put the edit form in a user control and display / hide it in a lightbox style.

0
source

Not sure if this is exactly what you want, but you could use cross-publishing for this. This allows you to return to the parent page from the child page with the advantage of accessing the ViewState child page. To do this, you set the PostBackUrl property of the button on the child page. On the parent page, you can access the PreviousPage property to retrieve values ​​from the child page. Thus, there is a button on the child page, for example:

 <asp:Button ID="Button1" runat="server" Text="Update data" PostBackUrl="~/Parent.aspx" onclick="Button1_Click" /> 

Then in the Parent.aspx Page_Load event:

 protected void Page_Load(object sender, EventArgs e) { if (IsCrossPagePostBack) { Page prevPage = this.PreviousPage; string myVal = prevPage.FindControl("myTextBox1").ToString(); string myVal2 = prevPage.FindControl("myTextBox2").ToString(); //etc } } 
0
source

All Articles