Important alert: (current site time 7/15/2013 7:29:58 AM EDT)
 

article

How To: Modal Dialogs in ASP.NET

Email
Submitted on: 4/14/2004 3:32:44 PM
By: Wayland Young 
Level: Intermediate
User Rating: By 17 Users
Compatibility: C#, ASP.NET
Views: 53142
(About the author)
 
     This tutorial begins with basic HTML showing how to set data on a Modal Dialog and return that data to the original page using Javascript. There are a few tricks which will be illustrated that you'll have to use if you want to get the same functionality with ASP.NET pages. I've seen similar tutorials and samples on the web. Some claim to have modal dialogs but still allow clicking on the main window. Most don't show how to return multiple values from the dialog. Included in the .zip file is a web page called Instructions.htm which (you guessed it) includes tutorial instructions. The HTML source is in the HTML directory and the ASP.NET (C#) Project is in the DialogAspx directory. I have only tested on Internet Explorer 6.0 but I believe it will also work on IE 5.0. Please rate and post comments. Enjoy!

This article has accompanying files

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				Planet Source Code doesn't allow HTML tags anymore :(
See Instructions.htm

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/15/2004 9:13:12 AMChristina McEntire

Very useful! Thanks. :)
(If this comment was disrespectful, please report it.)

 
6/3/2004 2:28:48 PMMarcelo Valle Franco

Clear explanation! Good trick! Thanks.
(If this comment was disrespectful, please report it.)

 
11/6/2004 8:06:35 AM

when i put your code in my iis server of windows 2000,in local machine it is very good.
but when i access the page from other pc(win98,ie5.0),i click then ok button of child windows,the other child window display.
can you tell me how to solve the problem. thank you very much.
(If this comment was disrespectful, please report it.)

 
2/10/2005 4:59:04 AMPradeep Panzade

I want to know how your this project will work in ASP.NET using VB.NET
(If this comment was disrespectful, please report it.)

 
3/3/2005 9:04:37 AMWayland Young

There is very little C# code in the project as it is mostly javascript. The only thing you need to know is how to add an attribute to a button.

In C# the syntax is:
button.Attributes["onclick"] = "javascript: return Function();";
OR
button.Attributes.Add("onclick", "javascript: return Function();");

In VB it's:
button.Attributes("onclick") = "javascript: return Function();"
OR
button.Attributes.Add("onclick", "javascript: return Function();")
(If this comment was disrespectful, please report it.)

 
9/9/2005 10:45:34 AMSteve Swann

This sample/tutorial is fantastic! But, I had to change the child.aspx body section to this:

BODY onLoad="javascript:GetData()"; MS_POSITIONING="GridLayout"

The difference from the sample is the addtion of "javascript:" before GetData().
Without that I got an error in the script on this page... "Object Expected".

Works 100% with that (VS.NET 2003) I can go crazy with dialogs to get user input now!
(If this comment was disrespectful, please report it.)

 
9/9/2005 10:56:35 AMSteve Swann

Wait! My bad! I didn't realize that the onload=gETdATA() was cASE sENSTIVE! Forget that javascript: thing I added. It works with or without it. I had getdata() not GetData(). Sorry!
(If this comment was disrespectful, please report it.)

 
12/27/2005 6:07:25 AMmr

Very helpfull, many thanks.
(If this comment was disrespectful, please report it.)

 
2/15/2006 10:37:22 AMTracy Wilson

Excellent... very useful!
(If this comment was disrespectful, please report it.)

 
8/4/2006 1:55:32 AMsaravanaperumal.c

this code is very simple and useful. thank you.
(If this comment was disrespectful, please report it.)

 
8/27/2009 3:24:56 PMMilton Sozezzo

Fantastic... good job...
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.