【问题标题】:Passing data from a aspx page to a aspx popup将数据从 aspx 页面传递到 aspx 弹出窗口
【发布时间】:2012-06-25 12:49:32
【问题描述】:

以下是我所面临的场景,我有一个 aspx 页面,我在其中添加了我的 ascx 用户控件,我还有一个 <a href 控件,它调用一个 js 函数来打开一个 aspx 弹出窗口。

当我打开弹出窗口时,我需要将 ascx 控件中的数据发送到我的弹出窗口。你能指导我使用什么方法来实现这一点,而不是使用会话,因为数据可以在许多不同的地方更新,因此在会话中维护会很困难。

谢谢

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    尝试使用这些语法(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);
    

    【讨论】:

    • 对不起,错过了,我必须传递的数据是大查询字符串是不够的。
    【解决方案2】:

    你说你是用js函数打开aspx弹窗的。

    那么就很简单了。

    1.使用javascript从User控件的控件中读取数据 var variable1 = document.getElementByID("ControlId").value; var variable2 = document.getElementByID("ControlId").value; 2. 将此数据作为查询字符串传递到下一页 window.open("http://www.w3schools.com?id=" + variable1 + "&name=" + variable2); 您可以从下一页的查询字符串中读取此数据

    【讨论】:

    • 你好 Mohammed,如果你的控件是 asp.net 控件,你可以为你的第一个脚本添加 ClientId
    【解决方案3】:
    如果您无法将数据作为查询字符串发送,可以尝试其他一些方法
    
    1. 尝试使用 target="_blank" 将表单发布到其他页面。
       如果需要,我们可以动态更改表单操作。
    或者
    2. 利用弹出窗口中的 window.opener 对象从控件打开页面中读取数据。
      var variable1 = window.opener.getElementById("ControlId").value
    

    【讨论】:

      【解决方案4】:

      在你的 ascx 中创建一个隐藏变量。

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

      在 ascx 的页面加载时设置要发送到隐藏变量的值

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

      在后面的代码中注册一个 ajax 管理器。

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

      在 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
              }
          }
      

      我使用 Telerik,它对管理弹出窗口有很大帮助。让我知道,如果这有帮助。

      干杯!

      【讨论】:

        猜你喜欢
        • 2010-09-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-02
        • 2014-12-23
        • 1970-01-01
        相关资源
        最近更新 更多