Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

JavaScript
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(data);


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


Here I'm using session but , I'm not able to get value in session , it says "undefined"
Posted

1 solution

That's not how ASP.NET works - you can't call server-side code from script like that.

ASP.NET receives a request from the client. It executes code - including anything inside a <% ... %> or <%= ... %> block - and generates a response which is sent to the client. The javascript code then executes on the client.

Your javascript Receivedata variable will contain the value of the session variable when the page was first requested. If a subsequent request changes the session variable, that change will not be visible to your javascript unless you reload the page.

Your "child form" page sets the session variable to the literal string "' + senddata + '" when the page loads. It does not know anything about the javascript variable called "senddata".

Also, showModalDialog was removed from Chrome May[^], and from Firefox in June[^]. It's deprecated in IE11, and not supported in Microsoft Edge.

There are various options to replace this deprecated method - for example, these two[^] polyfills[^].

You would then rewrite your code to use window.returnValue in the child form to return the data to the parent form:
JavaScript
// Parent form:
var data = window.showModalDialog(sURL, "Lookup", sFeatures1, true);
alert(data);

// Child form:
window.returnValue = data;
window.close();
 
Share this answer
 
Comments
King Fisher 26-Aug-15 13:50pm    
thanks,this what i have tried,yes it is working. +5
King Fisher 26-Aug-15 15:48pm    
but my parent form all Controls are automatically reset as empty.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900