5,695,118 members and growing! (13,245 online)
Email Password   helpLost your password?
Web Development » Custom Controls » General     Intermediate

ModalDialogHelper Control in ASP.NET 1.1 and 2.0

By Rouser

An ASP.NET control that helps you to transfer data between a dialog page and its invoker page.
C#, Windows, .NET 1.1, .NET, ASP.NET, Visual Studio, VS.NET2003, VS2005, Dev

Posted: 22 Aug 2005
Updated: 16 Jun 2006
Views: 80,198
Bookmarked: 65 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
17 votes for this Article.
Popularity: 5.40 Rating: 4.39 out of 5
0 votes, 0.0%
1
2 votes, 11.8%
2
2 votes, 11.8%
3
2 votes, 11.8%
4
11 votes, 64.7%
5

Introduction

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:

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

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:

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)
{
    this.DialogHelperControl1.ShowDialog("WebForm2.aspx",
                                TextBox2.Text,500,300,false);
}

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:

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)+
                      Convert.ToInt32(TextBox2.Text)).ToString();
}

private void Button2_Click(object sender, System.EventArgs e)
{
    this.DialogHelperControl1.ReturnAndCloseDialog(TextBox3.Text);
}

private void Button3_Click(object sender, System.EventArgs e)
{
    this.DialogHelperControl1.CloseDialog();
}

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.

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

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

History

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

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

Rouser


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

Enjoy your coding !
Occupation: Web Developer
Location: China China

Other popular Custom Controls 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 25 of 61 (Total in Forum: 61) (Refresh)FirstPrevNext
Questionasp.net 1.1: How to configure the control to work in a modal mode.membershmuliktal554:27 5 Aug '07  
GeneralUser controlsmemberajds2:41 11 Jun '07  
Generalpassing multiple parameters?memberUnruled Boy22:39 8 Jun '07  
QuestionModalDialogHelpermembertal1245786:33 2 May '07  
GeneralGetting problem with AJAX and ModalDialogHelper controlmembersunil_limje2:35 19 Mar '07  
GeneralRe: Getting problem with AJAX and ModalDialogHelper controlmemberRouser0:47 21 Mar '07  
Generalasp.net document.body is null or not an objectmemberTHEMANJD11:42 27 Dec '06  
GeneralRe: asp.net document.body is null or not an objectmemberjosef volkman6:12 22 Jan '07  
GeneralCalling one modal dialog from another - problem?memberfinman436:38 8 Dec '06  
GeneralRe: Calling one modal dialog from another - problem? [modified]memberATLShogun7:33 8 Jan '07  
GeneralSmartNavigation & IFramememberJoey Chömpff0:08 14 Nov '06  
QuestionHow to stop validation on Modal returnmemberrmgsantos@hotmail.com7:51 20 Oct '06  
Generalwhy does it not work with model typememberhonglixing16:17 28 Sep '06  
GeneralUndable to run in asp.net 1.1 (2)memberhialmeyd11:14 11 Sep '06  
GeneralUndable to run in asp.net 1.1memberhialmeyd11:09 11 Sep '06  
Generalsome suggestionmembertangsg20:43 31 Aug '06  
GeneralRe: some suggestionmemberRouser21:37 31 Aug '06  
QuestionRe: some suggestionmemberATLShogun7:05 8 Jan '07  
QuestionRe: some suggestionmemberATLShogun7:05 8 Jan '07  
General'Form1' is undefined errormemberendosearchMatt11:34 2 Aug '06  
GeneralRe: 'Form1' is undefined errormemberibgvfdfyoroqrf5:22 30 May '07  
Questiontry add ModalDialogHelper in code at run time?memberJoao Norte5:39 2 Aug '06  
AnswerRe: try add ModalDialogHelper in code at run time?memberRouser19:14 2 Aug '06  
GeneralUndable to run in asp.net 1.1memberravihd19:02 27 Jun '06  
GeneralRe: Undable to run in asp.net 1.1memberRouser15:40 28 Jun '06  

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

PermaLink | Privacy | Terms of Use
Last Updated: 16 Jun 2006
Editor: Smitha Vijayan
Copyright 2005 by Rouser
Everything else Copyright © CodeProject, 1999-2008
Web08 | Advertise on the Code Project