Tuesday, January 29, 2008

Tip: Closing an IE Modal Dialog

It's a tedious and time consuming task to find out actually how to close an IE modal dialog generated by calling the ShowModalDialog Javascript function. To make things short, i present only the codes:


//To show the modal dialog.
function DisplayMenu()
{
var url = "page.aspx";
var winName = "ProblemReportActions";
var height = 280;
var width = 500;
var returnedValue = '';
var params = '';
var returnedValue = ShowModalWindow( url, winName, width, height,params);
if(returnValue != null)
{
postBack(returnValue); //Javascript Post Back for the main window
}
}

//In the C# aspx page add the onclick attributes to the button to close the dialog.
//the first button actualy close the dialog and returns something to the main window.
//the second button basically closes the dialog like a cancel button.
this.bt_ok.Attributes.Add("onclick", "closeDialog('" + this.txtOption.UniqueID + "');return false;");
this.bt_cancel.Attributes.Add("onclick", "window.close();return false;");

No comments: