Skip to main content
Email Password   helpLost your password?

Introduction

This article presents how to open modal dialog window on browser(IE browser only), which contains a web form. Submitting the form on modal dialog window will refresh the main window content.

Background

I was presented with a project to convert a Windows application into a Web-based application. The Windows application's main form displays a datagrid. Clicking on row of datagrid opens a modal dialog window which helds detail information about that datagrid row record. User can edit the data on modal dialog window and cliking on Update button close the dialog and refreshes the datagrid on main form. The client wants same effect in web application. After much long R & D i came with the solution which i want to share with you.

How to open Modal Dialog window and How to get return value from it?

Since I have no time , my source project contains all code in one file (Sorry! no separate businesslogic or dataaccess logic classes given).

First of all look at the javascript code for opening modal window (OpenModalDialog function in Default.aspx page). The line:

 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 contains return value of modal dialog window(when close), which we can set in ModalWindow form by (in detail.aspx page).

window.returnValue = true; //(i am returning true to refresh Main page and false for no action)

You can give any value to return

Important thing: making post back from javascript

The most important thing for me is to refresh the grid when i get 'true' as return value from modal window. For that i have written (keep looking in javascript's OpenModalDialog function )

__doPostBack(btnName,''); //(this will trigger 'btnName' butoon's Click event)

See in default.aspx page i have used btnAddNew to add new data. using above javascript i can fire the click event of this button.

Note :To make this working you have to set the default.aspx page's attibute EnableEventValidation to False. Setting this attribute value to false enables us to fire postback (server side events) using javascript.

Announcement

Any suggesions and additional functionality to improve this code is heartly wel come. Feel free to ask any questions related to this article. Thanks...

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Questionwhy do dialogLeft and dialogTop not work with IE7 (works with firefox3.53)? Pin
lhq2100
9:24 24 Sep '09  
GeneralProblem with window.returnValue in safari Pin
mynameissuraj
23:58 20 Oct '08  
GeneralFiring other events for postback after the popup Closes Pin
Ammar Hassan
23:26 5 Mar '08  
QuestionA standards compatible cross browser (non IE-only) version Pin
volkan.ozcelik
8:53 15 Feb '07  
Generalaccess to parent window from dialog Pin
mburnie
22:53 17 Jul '06  
AnswerRe: access to parent window from dialog Pin
Kiran Beladiya
3:40 18 Jul '06  
GeneralRe: access to parent window from dialog Pin
mburnie
5:24 18 Jul '06  
GeneralRe: access to parent window from dialog Pin
light169
22:51 18 Jul '06  
GeneralRe: access to parent window from dialog Pin
mburnie
0:18 20 Jul '06  
GeneralRe: access to parent window from dialog Pin
light169
1:08 20 Jul '06  
GeneralRe: access to parent window from dialog Pin
mburnie
3:02 20 Jul '06  
GeneralRe: access to parent window from dialog Pin
Kiran Beladiya
23:22 21 Jul '06  
GeneralRe: access to parent window from dialog Pin
mburnie
6:55 14 Aug '06  
GeneralRe: access to parent window from dialog Pin
Paul Peeters
10:13 23 Aug '06  
GeneralRe: access to parent window from dialog Pin
anhtn
16:47 5 Jun '08  
AnswerRe: access to parent window from dialog Pin
mburnie
0:32 6 Jun '08  
GeneralRe: access to parent window from dialog Pin
mayurmv
18:20 1 Sep '08  


Last Updated 5 Feb 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009