5,545,925 members and growing! (17,761 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

ShowModalDialog effect in ASP.NET web forms

By Kiran Beladiya

How to open modal dialog window in browser (Internet explorer) and do something with parent window when return
Javascript, SQL, VB, Windows, .NET 2.0, .NET, Visual Studio, ASP.NET, DBA, Dev

Posted: 12 Jul 2006
Updated: 5 Feb 2007
Views: 68,343
Bookmarked: 33 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
9 votes for this Article.
Popularity: 3.30 Rating: 3.46 out of 5
2 votes, 22.2%
1
0 votes, 0.0%
2
1 vote, 11.1%
3
3 votes, 33.3%
4
3 votes, 33.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Kiran Beladiya



Occupation: Web Developer
Location: India India

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 15 of 15 (Total in Forum: 15) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralFiring other events for postback after the popup ClosesmemberAmmar Hassan23:26 5 Mar '08  
QuestionA standards compatible cross browser (non IE-only) versionmembervolkan.ozcelik8:53 15 Feb '07  
Generalaccess to parent window from dialogmembermburnie22:53 17 Jul '06  
AnswerRe: access to parent window from dialogmemberKiran Beladiya3:40 18 Jul '06  
GeneralRe: access to parent window from dialogmembermburnie5:24 18 Jul '06  
GeneralRe: access to parent window from dialogmemberlight16922:51 18 Jul '06  
GeneralRe: access to parent window from dialogmembermburnie0:18 20 Jul '06  
GeneralRe: access to parent window from dialogmemberlight1691:08 20 Jul '06  
GeneralRe: access to parent window from dialogmembermburnie3:02 20 Jul '06  
GeneralRe: access to parent window from dialogmemberKiran Beladiya23:22 21 Jul '06  
GeneralRe: access to parent window from dialogmembermburnie6:55 14 Aug '06  
GeneralRe: access to parent window from dialogmemberPaul Peeters10:13 23 Aug '06  
GeneralRe: access to parent window from dialogmemberanhtn16:47 5 Jun '08  
AnswerRe: access to parent window from dialogmembermburnie0:32 6 Jun '08  
GeneralRe: access to parent window from dialogmembermayurmv18:20 1 Sep '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Feb 2007
Editor:
Copyright 2006 by Kiran Beladiya
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project