[英]How to pass values from an asp.net child page to the parent page
I have two web pages, Page1
and Page2
, which can both open the same child popup page. 我有两个网页,
Page1
和Page2
,它们都可以打开相同的子弹出页面。
If the parent page is Page1
I want certain input from the Child page to returned to the parent page and if the parent page is Page2
I want other information to be returned. 如果父页面是
Page1
我希望Child页面中的某些输入返回到父页面,如果父页面是Page2
我希望返回其他信息。
I do identify who is the parent page and how do I return the input to it and have it show in the proper text box or DroDownList? 我确定谁是父页面,如何将输入返回给它并将其显示在正确的文本框或DroDownList中?
I tried using Request.UrlReferrer
putting results in a string variable and I got an error 'object not set to an instance'. 我尝试使用
Request.UrlReferrer
将结果放入一个字符串变量,我得到一个错误'对象未设置为实例'。
As both the pages can be parent , write the a javascript function that works as receiver on both the page and write code in it as per your requirement. 由于两个页面都可以是父页面,因此请在页面上编写一个javascript函数作为接收器,并根据您的要求在其中编写代码。
eg 例如
javascript on Parent page: 父页面上的javascript:
SetDataFromPopup(data)
{
document.getElementById('TextBox1ClientId').value = data;
}
On popup write the following line 在弹出窗口中写下以下行
window.opener.SetDataFromPopup(data);
this should be called on the event where you want to pass the data eg suppose you have a button on client click of it you want to pass the data , the code should look like: 这应该在您想要传递数据的事件上调用,例如假设您在客户端点击它想要传递数据的按钮,代码应如下所示:
<input id="btnSave" type="submit" onclick="window.opener.SetDataFromPopup(data);" >Save</input>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.