dialog box in some applications, you want to echo (postback) The value of the modal dialog box to the server, which is to perform a service-side operation to refresh the page.
For example: Create a New order, at this time want to be able to select the product in the modal dialog box, and the product ID return, while refreshing the product items in the order, there are many ways to solve, here only the way to perform server operations.
To send the client data back (postback) to the server and perform the appropriate action, it is obvious that you must submit the form and set the value of the hidden field __eventtarget, but ASP.net has done this for us, as long as you call __doPostBack with the appropriate parameters.
Another problem is how to pass the value of the modal dialog box to the server, which is all right, there are several ways to save the value with a hidden field, of course, this hidden field must be runat= "server" attribute.
Some of the code is given below:
Main Page testdialog.aspx:
<form id= "Form1" runat= "Server" >
<input type= "hidden" id= "TxtValue" runat= "Server"/>
<br/>
<asp:linkbutton id= "Lbtnopen" runat= "Server" text= "Open dialog box"/>
<br/>
dialog box return value: <asp:textbox id= "txtValue2" runat= "Server"/>
</form>
Main Page post file TestDiallg.aspx.cs:
private void Page_Load (object Sender, EventArgs e) {
StringBuilder sb = new StringBuilder ();
if (! IsClientScriptBlockRegistered ("ClientScript")) {
Sb. Append ("<script language= ' JavaScript ' >\n")
. Append ("function addproduct () {\ n")
. Append ("var ret = window.showmodaldialog (' test2.aspx ');" \ n ")
. Append ("if (ret!= undefined) {\ n")
. Append ("document.getElementById" ("+ Txtvalue.clientid +"). Value = RET \ n ")
. Append ("__dopastback (' + Lbtnopen.uniqueid +" ', '); \ n ")
. Append ("} \ n")
. Append ("}\n")
. Append ("</script>\n");
RegisterClientScriptBlock ("ClientScript", sb.) ToString ());
}
LBTNOPEN.ATTRIBUTES.ADD ("OnClick", "javascript:addproduct ();");
}
private void Lbtnopen_click (object Sender, EventArgs e) {
Txtvalue2.text = Txtvalue.value;
}
private void InitializeComponent ()
{
This. Load + = new EventHandler (this. Page_Load);
This.lbtnOpen.Click + = new EventHandler (This.lbtnopen_click);
}
dialog box Page test2.aspx:
<form id= "Form1" runat= "Server" >
<asp:textbox id= "TxtValue" runat= "Server"/>
<br/>
<input type= "button" id= "Hlnkok" value= "OK" runat= "Server"/>
</form>
dialog box page post file Test2.aspx.cs
private void Page_Load (object Sender, EventArgs e) {
StringBuilder sb = new StringBuilder ();
if (! IsClientScriptBlockRegistered ("ClientScript")) {
Sb. Append ("<script language= ' JavaScript ' >\n")
. Append ("function closedialog () {\ n")
. Append ("window.returnvalue = document.getElementById (' + Txtvalue.clientid + '). value;\n")
. Append ("window.close (); \ n")
. Append ("}\n")
. Append ("</script>\n");
RegisterClientScriptBlock ("ClientScript", sb.) ToString ());
}
HLNKOK.ATTRIBUTES.ADD ("OnClick", "Javascript:closedialog ();");
}