Friday, September 2, 2011

Call parent window methods form dialog popup window

Main form code:

fuction openPopup()
{
var argObj= window;
window.showModelDialog("child.html",argObj,"dialogHeight:500px;dialogWidth:500px");
}
function CallMe()
{
alert("This is Parent Window");
}
//Child.html

function callParentMethod()
{
alert("Child.hml");
var objArg= window.dialogArguments;
objArg.CallMe(); // objArg.CallMe is equilent to window.CallMe()
}

this was one way but we have one limitation with it because modal dialog box can have only 4096 characters; longer strings are truncated. So if argObj is larger it can affect our height and width property.

Other way is to use Result send by child.html(popup Modal)
For Ex:

fuction openPopup()
{
var argObj= window;
var dialogResult=window.showModelDialog("child.html",argObj,"dialogHeight:500px;dialogWidth:500px");
// once child window has been closed
alert( dialogResult.firstVar);
alert( dialogResult.secondVar);
if(dialogResult.callMe)
{
CallMe() ;
}

}
function CallMe()
{
alert("This is Parent Window");
}
//Child.html

// On Close
function callParentMethod()
{
 alert("Child.hml");
 var resultVariable;
 resultVariable.firstVar='';//set some values if required
 resultVariable.secondVar='';//set some values if required
result.callMe=" call it ";// if you wants to call method of parent window otherwise you can remove this statement

 window.result= resultVariable;
this.close();
}


Happy Living ....
Happy Coding...
Happy Concepts........

No comments:

Post a Comment