Introduction
This article presents how to open a modal dialog window on a browser (IE only) which contains a web form. Submitting the form on the modal dialog window will refresh the main window content.
Background
I was working on a project to convert a Windows application into a Web-based application. The Windows application's main form displays a DataGrid
. Clicking on a row of the DataGrid
opens a modal dialog window which holds detailed information about that DataGrid
row record. The user can edit the data on the modal dialog window, and clicking on an Update button closes the dialog and refreshes the DataGrid
on the main form. The client wanted the same effect in the web application. After much R & D, I came with a solution which I want to share with you.
How to open a modal dialog window and how to get a return value from it?
Since I have no time, my source project contains all the code in one file (sorry! no separate business logic or data access logic classes given).
First of all, let's look at the JavaScript code for opening a modal window (the OpenModalDialog
function in the Default.aspx page):
vReturnValue = window.showModalDialog(url,"#1","dialogHeight: 300px; dialogWidth: 600px;" +
"dialogTop: 190px; dialogLeft: 220px; edge: Raised; center: Yes;" +
"help: No; resizable: No; status: No;");
The vReturnValue
variable will contain the return value of the modal dialog window (when closed), which we can set in the ModalWindow
form (in the detail.aspx page).
window.returnValue = true;
You can give any value to be returned.
Postback from JavaScript
The most important thing for me is to refresh the grid when I get 'true' as the return value from the modal window. For that, I use (look in JavaScript's OpenModalDialog
function):
__doPostBack(btnName,'');
In the default.aspx page, I have used btnAddNew
to add new data. Using the above JavaScript, I can fire the Click event of this button.
Note :To make this work, you have to set the default.aspx page's EnableEventValidation
attribute to False
. Setting this attribute to false enables us to fire a postback (server side events) using JavaScript.
Request
Any suggestions and additional functionality to improve this code is heartily welcomed. Feel free to ask any questions related to this article. Thanks...
The One Technologies is a software development company in India. The One Technologies specializes in delivering state-of-the-art solutions in software development, web development, web application and Rich Internet Application (RIA) development, iPhone development, and robust and secure business processing infrastructures. Software development tools and technologies used extensively at The One Technologies include Microsoft .NET architecture, PHP/MySQL frameworks, Adobe Flex, Microsoft Silverlight, Microsoft SharePoint and BizTalk Servers, and Microsoft CRM and XRM platforms.