简体   繁体   English

如何使用JavaScript将数据发送回asp.net中的调用页面

[英]How to send back the data to calling page in asp.net using javascript

Here I'm opening a new window then i will do some operations and i want to send back the data to main from from child form 在这里我打开一个新窗口,然后我将执行一些操作,我想将数据从子窗体发送回main

Main form: 主要形式:

var sURL = 'AnodizingLoadingPopupHelp.aspx' +
                         '?ProfitCenterCode=' + strProfitCenterCode +
                          '&LineCode=' + MachineID;

                var sFeatures1 = "dialogHeight: 240px;dialogWidth:280px;dialogLeft:40px;dialogTop:100px";

                window.showModalDialog(sURL, "Lookup", sFeatures1, true);

                var Receivedata = '<%= Session["data"] %>';
                alert(Receivedata );

Child form: 子表格:

var senddata = data;
                '<%Session["data"] = "' + senddata + '"; %>';
                 alert(senddata);
                 window.close();

Here I'm using session but , I'm not able to get value in session , it says "undefined" 在这里我正在使用会话,但是,我无法在会话中获得价值,它说“未定义”

Traditionally, Query String is used to pass values like this. 传统上, 查询字符串用于传递这样的值。

protected void Page_Load(object sender, EventArgs e)
{
    string v = Request.QueryString["param"];
    if (v != null)
    {
        Response.Write("param is ");
        Response.Write(v);
    }
}

But in cases where Query String won't do, such as interfacing with some other application, it's best to use a HTML control that is set to hidden. 但是在无法使用查询字符串的情况下(例如与某些其他应用程序接口),最好使用设置为隐藏的HTML控件。 Don't forget to account for cross browser issues : 不要忘记考虑跨浏览器的问题

function getElement (id) {
  if (document.getElementById) {
    return document.getElementById(id);
  }
  else if (document.all) {
    return window.document.all[id];
  }
  else if (document.layers) {
    return window.document.layers[id];
  }
} 

If you do not have a runat=server on the control, And get the control like this : 如果您的控件上没有 runat=server ,则获取这样的控件:

 myValue = getElement ("#myControlID").value;

Otherwise, if you did use the runat=server property on your control, then you can get it in javascript like this : 否则,如果您确实在控件上使用了runat=server属性,则可以像下面这样在javascript中获取它:

myValue= getElement('<%= HiddenStatusFlag.ClientID%>').value; 

( see here: Get Value of Hidden Field in Client Side ) (请参见此处: 在客户端获取隐藏字段的值

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

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