0

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 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"

King_Fisher
  • 1,171
  • 8
  • 21
  • 51

1 Answers1

0

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. 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 :

 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 :

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

( see here: Get Value of Hidden Field in Client Side )

Community
  • 1
  • 1
rlb.usa
  • 14,942
  • 16
  • 80
  • 128
  • I cant use Querystring , I dont want to Refresh the mail form. – King_Fisher Aug 26 '15 at 16:00
  • @King_Fisher have you looked at `UpdatePanel`s ? – rlb.usa Aug 26 '15 at 16:26
  • i cant use ,because im calling that child form middle of my main form, if i refresh the page , again I have to fill all controls in main form – King_Fisher Aug 26 '15 at 16:34
  • @King_Fisher That's not how `UpdatePanel`s are supposed to work, they let you selectively update a section of controls (or all the controls, whatever) without loosing the session state (the filled out controls). If you are using UpdatePanels already, it sounds like something's wrong. But it sounds like you will need to look into them very soon for your project. – rlb.usa Aug 26 '15 at 16:43
  • Thanks,It is solved here: http://www.codeproject.com/Answers/1022368/How-Do-I-Send-Back-The-Data-To-Calling-Page-In-Asp#answer1 – King_Fisher Aug 26 '15 at 17:52