从后面的子页面代码中调用方法后面的父页面代码-ASP.NET 2.0页面继承模型 [英] Calling a parent page code behind method from a child page code behind - ASP.NET 2.0 Page Inheritance model

查看:65
本文介绍了从后面的子页面代码中调用方法后面的父页面代码-ASP.NET 2.0页面继承模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从ASP.NET 2.0网站模型的子页面后面的代码中调用父页面代码后面的方法的最佳方法是什么?

What would be the best way to call a method in the code-behind of parent page from the code behind of the child page in the ASP.NET 2.0 Web Site model?

方案:用户单击父页面中的链接以在子页面中查看数据记录的详细信息(父和子是两个单独的页面).用户将修改客户端页面中的数据.子页面处理完更新后,子页面将关闭,我需要重新绑定父页面以反映更新.

Scenario: User clicks a link in the parent page to view a data record's detail in child page (The parent and child are tow seperate pages). The user will modified the data in the client page. Once the child page has processed the update, the child page will close and I need to rebind the parent page to reflect the update.

我做了类似的事情,但是它是从父页面中包含的用户控件中调用父页面的

I did something similar, but it was calling 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 the code behind because the child page closes after the data has been updated.

推荐答案

最简单的方法是使用多视图或类似方法在一页上完成整个工作.

Easiest way would be to do the whole thing on one page using a multiview or some such thing.

除此之外,您可以使用javascript调用

Other then that, with javascript you can call

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

更改父页面上的URL.您可以保持不变,也可以将内容粘贴在查询字符串中,然后将这些值与Page_Load中的值混为一遍

to change the url on the parent page. You could just keep it the same, or stick stuff in the query string and muck with those values on Page_Load

这篇关于从后面的子页面代码中调用方法后面的父页面代码-ASP.NET 2.0页面继承模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆