Using window.showModalDialog
To send parameters to the child page, use query string.
If the window is opened using window.showModalDialog (instead of window,open), then parameters can be sent back to the parent page using window.returnValue.
Parent page javascript (send values using query string) :
[Note: This will not work with window.open]
Child page C# code (to accept query string parameters):
Child page javascript that returns the values:
Using window.open
If you are using window.open(url), in that case write a javascript function in the PARENT page that you want to call from the child page. Suppose the function is called Hello. This is how you will invoke it from child page.
window.opener.Hello();
To send parameters to the child page, use query string.
If the window is opened using window.showModalDialog (instead of window,open), then parameters can be sent back to the parent page using window.returnValue.
Parent page javascript (send values using query string) :
url = "/myChild?param1=hello¶m2=28";
var x = window.showModalDialog(url);
if (x) {
alert(x.Age);
}
else {
alert('no return data');
}
[Note: This will not work with window.open]
Child page C# code (to accept query string parameters):
string param1 = Request.QueryString[" param1"].ToString();
int param2 = int.Parse(Request.QueryString[" param2"]);
Child page javascript that returns the values:
var x = new Object();
x.name = 'Sam';
x.Age
= 37;
window.returnValue = x;
window.close();
Using window.open
If you are using window.open(url), in that case write a javascript function in the PARENT page that you want to call from the child page. Suppose the function is called Hello. This is how you will invoke it from child page.
window.opener.Hello();
No comments:
Post a Comment
Comments will appear once they have been approved by the moderator