简体   繁体   English

将数据从ASPX页面传递到ASPX弹出窗口

[英]Passing data from a aspx page to a aspx popup

Following is the scenario I am facing, I have a aspx page in which I have added my ascx user control, I also have a <a href control which call a js function to open a aspx popup. 以下是我面临的情况,我有一个aspx页面,其中添加了我的ascx用户控件,还有一个<a href控件,该控件调用js函数打开aspx弹出窗口。

when I open the popup, I need to send the data present in the ascx control to my popup. 当我打开弹出窗口时,我需要将ascx控件中存在的数据发送到弹出窗口。 can you please guide me what method can I use to achieve this other than using session, as the data can be updated in many different places hence maintaining in session will be difficult. 您能指导我使用会话以外的方法来实现此目的吗,因为可以在许多不同的地方更新数据,因此很难在会话中进行维护。

Thanks 谢谢

尝试使用以下语法(RegisterStartupScript + window.open)

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "newWindow", "window.open('Test.aspx?ID=" + _cId + "','_blank','status=1,toolbar=0,menubar=0,location=1,scrollbars=1,resizable=1,width=30,height=30);", false);

You said that you are using a js function to open the aspx popup. 您说您正在使用js函数打开aspx弹出窗口。

then it is simple. 那很简单。

1. Read the Data from the controls of the User control by using javascript
   var variable1 = document.getElementByID("ControlId").value;
   var variable2 = document.getElementByID("ControlId").value;

2. Pass this data as query string to the next page
   window.open("http://www.w3schools.com?id=" + variable1 + "&name=" + variable2);
You can read this data from querystring from the next page
If you cant sent data as querystring , can try some other ways

1. Try to post the form to the other page using target="_blank".
   we can dynamically change the form action if needed.
OR
2. Make use of the window.opener object from the popup to read the data from controls the opener page.
  var variable1 = window.opener.getElementById("ControlId").value

Create a hidden variable in your ascx. 在ascx中创建一个隐藏变量。

<asp:HiddenField runat="server" ID="hdnId" />

On page load of ascx set the value to be sent to the hidden variable 在页面加载ascx时,设置要发送到隐藏变量的值

protected void Page_Load(object sender, EventArgs e){    
    hdnId.Value = <value to be sent to pop-up>;
}

Register a ajax manager in the code behind. 在后面的代码中注册ajax管理器。

protected override void OnInit(EventArgs e)
{
    RadAjaxManager.GetCurrent(this.Page).ClientEvents.OnRequestStart = "ajaxMngr_RequestStart;";

    base.OnInit(e);
}

In the ajaxMngr_RequestStart() JS 在ajaxMngr_RequestStart()JS中

    function ajaxMngr_SA_RequestStart(sender, args) {
            var oPatId = "<%=hdnSendPatId.Value %>";
            //add code to open the pop-up, add oPatId as part of the URL
        }
    }

I use Telerik, which makes helps a lot in managing pop-ups. 我使用Telerik,这有助于管理弹出窗口。 Let me know, if this helps. 让我知道,如果有帮助。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM