|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis 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
You should write the code to open the dialog page in the 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
And in WebForm2.aspx, you can get the argument which is transferred from the invoker page in the event " 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
Please let me know if there are bugs in this article. Your feedback and advice are most welcome. History
|
||||||||||||||||||||||