سؤال

I have a parent ASP.NET page which has a link that opens a child ASPX page in the form of a popup.

I need to control the parent page from the popup page's code-behind. For example enablie/disable the visibility of a label in the parent page, or setting text value for a text box.

How can I accomplish this?

Code used to open the popup ASPX:

//JavaScript function:
function showPopup()
{
     var strReturn = window.open("TaxReportInputsForm.aspx",'popup','width=390,height=120');
}

Button code:

Page.ClientScript.RegisterStartupScript(GetType(), "popup", "showPopup();", true);
هل كانت مفيدة؟

المحلول

The problem that you have is that HTTP is stateless and so each HTTP request/page is handled entirely independently - this means that there is no way to directly modify what is rendered on the parent page while processing a request from the child page.

What you can do however is indirectly modify what is rendered by having the child write out some flags/information to some place that both the child and the parent page can access, and then having the parent page look at that information to determine what to render. There are loads of different places that you could store this state, e.g.

For example, your child page might write a ShowSomeLabel flag to a cookie in the code-behind, then when the child page returns to the client it forces a refresh of the parent page, then in the code-behind for the parent page it can read that flag from the cookie to determine what labels should be visible.

All of these methods will require at least some JavaScript to cause of refresh of the parent page, however some will need additional JavaScript to copy hidden field / query string values from the child page to the parent page before it submits. Exactly where and how you should store this information depends on your specific requirements.

نصائح أخرى

you can try to use javascript, suppose A.aspx is parent page and B.aspx is the open page, you can use "opener" to contronl DOM of A.aspx.

A.aspx link tag and javascript :

<a href="B.aspx" target="_blank">open page B</a>
<script type="text/javascript">
    function fun_A() {
        alert("hello");
    }
</script>

B.aspx

<input id="btnChild" type="button" value="call function in Page A" onclick="opener.fun_A();" />

when you open B.aspx from A.aspx, and click the button from B.aspx, you will see A.aspx alert message "hello".

hope this can help you.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top