Modal Dialog Box in Asp.net
Finally, I started writing B/S. Program . Today I encountered a problem: how to handle the modal dialog box. The specific requirements are as follows: click "add" on the selection page to bring up the modal dialog box. After adding a record in the dialog box, select "OK" to close the dialog box, update the data in the table on the home page.
There are many discussions on the modal dialog box on the Internet. I tried it for a day and found a better solution:
1. displayed dialog box: JScript Add the following to the script file:
Function Openeditwin (frmwin, width, height ){ VaR Me; // Pass the window object of the parent page as a parameter to the dialog box, so that the dialog box can manipulate the automatic refresh of the parent page. Me = Window; // The dialog box is displayed. Window. showmodaldialog (frmwin, me, 'dialogwidth = ' + Width + 'Px; dialogheight = ' + Height + 'Px; help: No; Status: no ')}
Call in C:
Cmdadd. Attributes. Add ( " Onclick " , " Javascript: openeditwin (' " + Session [ " Showform " ] + " ', 540,400) " );
Many methods are implemented using response. Write or registerstartupscript, but they all have problems, such as the blank page when the dialog box is displayed and the pop-up dialog box when the page is refreshed. In the dialog box, add:
FunctionOnsubmit ()//Force this window to submit {Document.form1.tar get="_ Self";}
2. Close the dialog box
Response. Write ( " <Script language = 'javascript '> " ); Response. Write ( " Window. Close () " ); Response. Write ( " </SCRIPT> " );
3. After the dialog box is closed, execute the update operation and add it to the closing event of the dialog box:
Response. Write ( " <Script language = 'javascript '> " ); Response. Write ( " Window. Close () " ); Response. Write ( " </SCRIPT> " );
4. Update table data on the home page. In the "add" button, addCode.
Session ["showform"] is the aspx file name in the dialog box. The content is very simple. Some text boxes are designed on the page for users to enter relevant information, as well as the "OK" and "cancel" buttons, when the "OK" button is selected, save the data in the text box to the database, and close the dialog box. If the "cancel" button is selected, the operation is canceled. I did a test according to your method and found that when you click the button in the pop-up dialog box, a non-modal page is always displayed, and the displayed content is the same as that in the pop-up dialog box. Why?
========================================================== ==================
Add
<Head>
<Title> </title>
<Base target = _ Self>
</Head> finally started to write the B/S program. Today I encountered a problem: how to handle the modal dialog box. The specific requirements are as follows: click "add" on the selection page to bring up the modal dialog box. After adding a record in the dialog box, select "OK" to close the dialog box, update the data in the table on the home page.
There are many discussions on the modal dialog box on the Internet. I tried it for a day and found a better solution:
1. displayed dialog box: JScript Add the following to the script file:
Function Openeditwin (frmwin, width, height ){ VaR Me; // Pass the window object of the parent page as a parameter to the dialog box, so that the dialog box can manipulate the automatic refresh of the parent page. Me = Window; // The dialog box is displayed. Window. showmodaldialog (frmwin, me, 'dialogwidth = ' + Width + 'Px; dialogheight = ' + Height + 'Px; help: No; Status: no ')}
Call in C:
Cmdadd. Attributes. Add ( " Onclick " , " Javascript: openeditwin (' " + Session [ " Showform " ] + " ', 540,400) " );
Many methods are implemented using response. Write or registerstartupscript, but they all have problems, such as the blank page when the dialog box is displayed and the pop-up dialog box when the page is refreshed. In the dialog box, add:
FunctionOnsubmit ()//Force this window to submit {Document.form1.tar get="_ Self";}
2. Close the dialog box
Response. Write ( " <Script language = 'javascript '> " ); Response. Write ( " Window. Close () " ); Response. Write ( " </SCRIPT> " );
3. After the dialog box is closed, execute the update operation and add it to the closing event of the dialog box:
Response. Write ( " <Script language = 'javascript '> " ); Response. Write ( " Window. Close () " ); Response. Write ( " </SCRIPT> " );
4. Update table data on the home page. In the "add" button, add the table update code.