Click here to Skip to main content
15,065,044 members
Articles / Web Development / ASP.NET
Posted 22 Aug 2005


74 bookmarked

ModalDialogHelper Control in ASP.NET 1.1 and 2.0

Rate me:
Please Sign up or sign in to vote.
4.53/5 (17 votes)
16 Jun 20063 min read
An ASP.NET control that helps you to transfer data between a dialog page and its invoker page.


This article shows an implementation of a server side control to transfer data between a modal dialog page and its invoker page.

Several days ago, I wrote an article "Transfer arguments between a modal page and an invoker page in ASP.NET 1.1". In that article, I had shown how to transfer an argument to a modal dialog and get the return value when the dialog is closed; I just want to explain how to implement that. Now, I wrap it into a server side control in ASP.NET 1.1. If you want to understand the way to implement this problem, you can check out my previous article the link of which is given above. Now, just follow me to see how to use this control :-). Download the source code and compile it. Create a new web application named TestDialogHelper. In WebForm1.aspx’s design window, right-click the toolbox and select "Add/Remove Item" to add the "DialogHelperControl.dll" that you have compiled. Then, an icon will be displayed in your toolbox like shown below:

Image 1

Drop it to your page, now you will see how the control looks at design-time:

Image 2

We want to invoke WebForm2.aspx as a modal dialog when we click Button1 on WebForm1.aspx. So, WebForm1.aspx is an invoker page. OK, set its ParentType to "InvokerPage" in the property grid:

Image 3

You should write the code to open the dialog page in the Click event of Button2, this control has an open method named "ShowDialog", and you can get the return value in the event "OnDialogReturn". See the code below:

private void DialogHelperControl1_OnDialogReturn(string str)
    this.TextBox1.Text = str;

private void Button1_Click(object sender, 
                                System.EventArgs e)

Here, your invoker page is completed. So easy! Now, you should build your dialog page "WebForm2.aspx". In this page, we implement a simple Add method and return the sum to the invoker page when it is closed. Set the property of the dialog helper control in the dialog page, like shown below:

Image 4

And in WebForm2.aspx, you can get the argument which is transferred from the invoker page in the event "OnArgumentSubmit". When all the things are done in this page, you should call the control’s "ReturnAndCloseDialog" method or "CloseDialog" method to return to the invoker page.

private void Button1_Click(object sender, System.EventArgs e)
    TextBox3.Text = (Convert.ToInt32(TextBox1.Text)+

private void Button2_Click(object sender, System.EventArgs e)

private void Button3_Click(object sender, System.EventArgs e)

private void DialogHelperControl1_OnArgumentSubmit(string str)
    this.TextBox1.Text = str;

Here, all the processes of transferring are done. If you download the demo project, you will find two sub-folders in your unpackaged folder. Make a folder "TestDialogHelper" as a virtual folder with the same name as in your IIS, and the control’s project in another folder "DialogHelperControl". Open the solution, now you can compile the code and run it.

Image 5

Image 6

Image 7

[Updated]: My friend asked me why not set the element's value in the client on dialog return, because in many cases, we only need the return value to be put into an element's value (as <input>) in the client. So, I added two properties to implement this function. "AutoPostBackWhenDialogReturn" controls whether the page will submit when the user closes the dialog. "ClientScriptOnDialogReturn" is just the client script code to execute when the user closes the dialog. You will not use <script> and </script> to wrap the code. In fact, it is the code of the client function "__ClientScriptOnDialogReturn" which is registered in the "OnLoad" event of the control.

Image 8

Please let me know if there are bugs in this article. Your feedback and advice are most welcome.


  • 2005-08-22: Created version 1.
  • 2005-08-25: Added functions that allow the user to execute the script on the client on dialog return.
  • 2006-05-18: Added property DialogType that allows a user to open a dialog in two ways: modal and modeless.


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

Web Developer
China China
When I encounter a problem, I am charmed.
When I make it out, I am cordial.

Enjoy your coding !

Comments and Discussions 1.1: How to configure the control to work in a modal mode. Pin
shmuliktal555-Aug-07 3:27
Membershmuliktal555-Aug-07 3:27 
GeneralUser controls Pin
ajds11-Jun-07 1:41
Memberajds11-Jun-07 1:41 
Questionpassing multiple parameters? Pin
Huisheng Chen8-Jun-07 21:39
MemberHuisheng Chen8-Jun-07 21:39 
QuestionModalDialogHelper Pin
tal1245782-May-07 5:33
Membertal1245782-May-07 5:33 
GeneralGetting problem with AJAX and ModalDialogHelper control Pin
sunil_limje19-Mar-07 1:35
Membersunil_limje19-Mar-07 1:35 
GeneralRe: Getting problem with AJAX and ModalDialogHelper control Pin
Rouser20-Mar-07 23:47
MemberRouser20-Mar-07 23:47 document.body is null or not an object Pin
THEMANJD27-Dec-06 10:42
MemberTHEMANJD27-Dec-06 10:42 
I am trying to call two web dialog screeens with your control.

First time through the web dialog is display and the user clicks save or closes the window.

If the used clicked save on the first dialog window, then the second one is displayed and then the rest of the app will continue on its merry way.

What is happening is when I go to the first window I get the message

document.body is null or not an object

I am not using any special controls or anything like that on this dialog, and no exactly sure what is going on.

This is 2.0 box

Also just wanted to let you know that this is a very useful control and was wondering if you had may any other enhancements to it since you last updated this page.Smile | :)
GeneralRe: document.body is null or not an object Pin
josef volkman22-Jan-07 5:12
Memberjosef volkman22-Jan-07 5:12 
QuestionCalling one modal dialog from another - problem? Pin
finman438-Dec-06 5:38
Memberfinman438-Dec-06 5:38 
AnswerRe: Calling one modal dialog from another - problem? [modified] Pin
ATLShogun8-Jan-07 6:33
MemberATLShogun8-Jan-07 6:33 
AnswerCalling one modal dialog from another - problem? Pin
tomwang20084-Dec-08 5:53
Membertomwang20084-Dec-08 5:53 
GeneralSmartNavigation & IFrame Pin
Joey Chömpff13-Nov-06 23:08
MemberJoey Chömpff13-Nov-06 23:08 
QuestionHow to stop validation on Modal return Pin
rmgsantos@hotmail.com20-Oct-06 6:51
Memberrmgsantos@hotmail.com20-Oct-06 6:51 
Generalwhy does it not work with model type Pin
honglixing28-Sep-06 15:17
Memberhonglixing28-Sep-06 15:17 
GeneralUndable to run in 1.1 (2) Pin
HUGO ALMEYDA11-Sep-06 10:14
MemberHUGO ALMEYDA11-Sep-06 10:14 
GeneralUndable to run in 1.1 Pin
HUGO ALMEYDA11-Sep-06 10:09
MemberHUGO ALMEYDA11-Sep-06 10:09 
Generalsome suggestion Pin
tangsg31-Aug-06 19:43
Membertangsg31-Aug-06 19:43 
GeneralRe: some suggestion Pin
Rouser31-Aug-06 20:37
MemberRouser31-Aug-06 20:37 
QuestionRe: some suggestion Pin
ATLShogun8-Jan-07 6:05
MemberATLShogun8-Jan-07 6:05 
QuestionRe: some suggestion Pin
ATLShogun8-Jan-07 6:05
MemberATLShogun8-Jan-07 6:05 
General'Form1' is undefined error Pin
endosearchMatt2-Aug-06 10:34
MemberendosearchMatt2-Aug-06 10:34 
GeneralRe: 'Form1' is undefined error Pin
niemkhuccuoi070130-May-07 4:22
Memberniemkhuccuoi070130-May-07 4:22 
Questiontry add ModalDialogHelper in code at run time? Pin
Joao Norte2-Aug-06 4:39
MemberJoao Norte2-Aug-06 4:39 
AnswerRe: try add ModalDialogHelper in code at run time? Pin
Rouser2-Aug-06 18:14
MemberRouser2-Aug-06 18:14 
GeneralUndable to run in 1.1 Pin
ravihd27-Jun-06 18:02
Memberravihd27-Jun-06 18:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.