Solution to re-open the new page when submitting the page in the window opened by the showmodaldialog Function
The business requirement is as follows: on a list page (listpage), click the button to open an editpage. In the displayed window, edit the information and click OK to save the information, close the pop-up window and refresh the listpage.
Open the Js in the pop-up window:
Function openpage () {var seqid = Document. getelementbyid ("hidid"). value; If (seqid! = "") {Var width = 650; var Height = 550; var left = eval (screen. width-width)/2; var Top = eval (screen. height-height)/2; var open_feature = "dialogwidth =" + width + "PX; dialogheight =" + height + "PX; left =" + Left + "PX; top = "+ TOP +" PX, toolbar = 0; menubar = 0; resizable = 0; location = 0; status = 0; "; var ret = Window. showmodaldialog (rootpath + "home/edit? Seqid = "+ seqid, window, open_feature); If (ret = 1) {window. location. href = rootpath + "home/Index"; // refresh the list page }}}
On the editpage page, click OK. The JS functions are as follows:
function Save() { var theForm = document.forms[0]; if (theForm && (!theForm.onsubmit || (theForm.onsubmit() != false))) { theForm.action = rootPath + "Home/Update"; theForm.submit(); }}
Corresponding server code:
[Validateinput (false)] [httppost] public void Update (addsupporthistorymodel) {// Save the database... // Close the response window after it is saved. write ("<SCRIPT type = \" text/JavaScript \ "> window. close (); window. returnvalue = 1 </SCRIPT> "); response. flush (); response. end ();}
Problems: Click "OK". A new blank window is displayed, and the edit window is not closed.
Solution: Add the following code to the head in the pop-up editing window to solve the problem.
<Base target = "_ Self"> </base>
In addition, Google Chrome does not support setting returnvalue directly for the showmodaldialog pop-up form. The alternative is to set window. opener. returnvalue in the pop-up window.
After the above Code is modified, it is as follows:
Open the Js in the pop-up window:
Function openpage () {var seqid = Document. getelementbyid ("hidid"). value; If (seqid! = "") {Var width = 650; var Height = 550; var left = eval (screen. width-width)/2; var Top = eval (screen. height-height)/2; var open_feature = "dialogwidth =" + width + "PX; dialogheight =" + height + "PX; left =" + Left + "PX; top = "+ TOP +" PX, toolbar = 0; menubar = 0; resizable = 0; location = 0; status = 0; "; var ret = Window. showmodaldialog (rootpath + "home/edit? Seqid = "+ seqid, window, open_feature); If (ret = undefined) {ret = Window. returnvalue; // *****} If (ret = 1) {window. location. href = rootpath + "home/Index"; // refresh the list page }}}
Corresponding server code:
[Validateinput (false)] [httppost] public void Update (addsupporthistorymodel) {// Save the database... // Close the response window after it is saved. write ("<SCRIPT type = \" text/JavaScript \ "> window. close (); window. returnvalue = 1; if (window. opener) {window. opener. returnvalue = 1 ;}</SCRIPT> "); response. flush (); response. end ();}