Solution to re-open the new page when submitting the page in the window opened by the showmodaldialog Function

Source: Internet
Author: User

 

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 ();}

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.