Modal Dialog Box (ASP/ASP. NET) (zz from other blogs)

Source: Internet
Author: User
ASP Modal Dialog Box

Finally, I 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:

Add the following to the Javascript script file:

Function openeditwin (frmwin, width, height)

{

VaR me;

// Pass the parent page window object as a parameter to the dialog box, so that the dialog box can manipulate the parent page to automatically refresh.

Me = window;

// Display the dialog box.

Window. showmodaldialog (frmwin, me, 'dialogwidth = '+ width + 'px; dialogheight =' + height + 'px; help: No; Status: no ')

}

Call in C:

Using Add. 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.

Add a JScript to the dialog box

Function1 onsubmit () // 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, perform the update operation.

In the Close event dialog box, add:

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.

ASP. NET pop-up window (dialog box)

The purpose of this article is to record the previous experience in using the pop-up window, and summarize the usage of the pop-up window based on the reading of some materials.

First, describe the requirement: In the information publishing system, a field of information is "column", and you need to select a topic from the multi-level column to publish an article. Considering the appearance of the user interface and the convenience of operations, we decided to place a button on the new information release page. After the user clicks the button, a window showing the column tree is displayed, you can select a topic in this window.

This raises the question to be discussed in this article: how to bring up a window? How do I transmit information between the parent window and the pop-up window?

Before answering these two questions, you must first point out that there are currently three methods to pop up the window (dialog box), which are:

  • Window. Open Method
  • Modeless Dialog Box
  • Mode dialog box

How to choose among the three methods and how to answer the first two questions in the last two methods are described in the Post-article. Therefore, the window. Open method is used to answer the question.

The following is a simple example of window. Open pop-up window:

<SCRIPT>

Function open_cate ()

{

Window. Open ("Openup. aspx", "", "toolbar = 0, location = 0, directories = 0, status = 0,

Menubar = 0, scrollbars = 1, resizable = 0, Left = 200, Top = 100, width = 250, Height = 400 ");


}

</SCRIPT>

We can see from the code that we can set the attributes of the pop-up window. If you want to pop up a window when you click a button, you need to call the JavaScript function in The onclick time of the button.

After resolving the pop-up window, we will discuss how to transfer information between pages.

The parent window transmits information to the pop-up window.

Here, I use the method of splicing parameters in the URL to pass information. The first parameter of window. Open is URL. we can add the parameter after URL, for example, 'openup. aspx? Parm1 = ABC & parm2 = <% = serversideparm %> '. In this way, you only need to input the querystring parameters in the pop-up window to dynamically pass information to the pop-up window.

Return the information in the pop-up window to the parent window.

The pop-up pass-through is mainly used for interaction with users. Therefore, it is very important to obtain the user's operation results for the pop-up window on the parent page. In fact, the implementation method here is also very simple, it is also through javascript: through window. opener to get the window object of the parent window, you can operate on the parent window, such as setting a value for a textbox.

Postscript

It took a whole afternoon to implement this simple interactive operation. The key was to be too unfamiliar with JavaScript. I thought it was the skill to do something on the server side. In fact, I made a big mistake.

In addition, if an error occurs when the object is null when the. NET Server Object is referenced in JS, it is likely that after the object is compiled, vs renames the control. I don't know at the beginning, it makes me suffer.

Dialog Box with or without Modes

See the following link:

The importance of a good dialog box

Http://www.microsoft.com/china/msdn/archives/technic/library/techart/dude09252000.asp

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.