Modal window usage Summary

Source: Internet
Author: User

Symptom:
1. When a parameter is passed to the modal window, the session (...) is displayed for the first time (..) This value. When the session is assigned another value, the modal window returns the previous value.
2. During the development process, the pages opened in the modal window will be automatically cached, making the program unable to enter the breakpoint, causing great trouble for program debugging.

Solution 1:
Clear CACHE on the current page,
Add
<% @ OutputCache Duration = "1" VaryByParam = "None" %>
You can disable the current page cache.
Solution 2:

Add a random number to the call connection so that the modal window is considered to be a different connection.

Example:

Var a = window. showModalDialog ("basedetail_ctl.jsp? Datetime = "+ new Date (). toString () + "& Year =" + strYear + "& Month =" + strMonth, "", "status: no; resizable: yes; dialogHeight: pixel PX; dialogWidth: 460px; unadorne: yes ");

Datetime = "+ new Date (). toString () is used to add a random number to the call connection so that the modal window is considered as a different connection.

 

Window. dialogArguments [0]. Relationship between open window and parent window

In the pop-up window of the parent window, enter window. showModalDialog ('subwindow. aspx ', window ,'....');
Note that the second parameter uses window, so that you pass the parent window object as a parameter to the Child window.
Then, the parent window object can be referenced through window. dialogArguments in the Child window.
I said to the upstairs, you can do whatever you want...
For example, you can refresh the parent form when the child form is closed. You can write it as follows:
Window. dialogArguments. location. href = window. dialogArguments. location. href;
Window. focus ();
Window. close ();
You can also call the functions in the main window:
Window. dialogArguments. Function Name ();

The new and modified windows need to be constantly popped up in the program. It is a pain to think every time you press the code. So, I just summarized it and threw the Module window pop-up into a common Function method for processing (which should have been done for a long time ).
Eg:
Public string ModalWindow (string openAspxPage, int width, int height)
{
String js = string. format ("javascript: window. showModalDialog (\ "{0} \", window, \ "status: false; dialogWidth: {1} px; dialogHeight: {2} px \") ", openAspxPage, width, height );
Return js;
}

I originally wanted to write it using StringBuilder, but it was really troublesome to write StringBuilder. I simply changed the string, but it didn't have much impact.
In addition, I wrote another method to close the page, which is rough and will be used.
Public string ClosePage ()
{
StringBuilder js = new StringBuilder ();
Js. Append ("<script language = \" JavaScript \ "> ");
Js. Append ("window. close ();");
Js. Append ("</script> ");
Return js. ToString ();
}

In the project, except for adding and modifying pages that are Aspx, the other pages are ascx.
It seems that the size of openApxPage is not well controlled, and the code written above is not suitable for the LinkButton control in the DataGrid Control, so you have to write another method to overload it.

When using the modal window, you must pay attention to three issues:
1. Make sure there are <base target = "_ self"> between 2. Response. Write (new Function (). ClosePage (); statement should be included in the event processing of the button on the pop-up page to close the current modal window.
3. Due to Humorous cache, If you modify data in the modal window, you will find that the data on the parent page is refreshed, but when you click the button again, when the modal window is popped up again, you will find that the content in the modal window is still the content of the previous time. After my experiment, after Manually changing the html code, click the pop-up modal window to bring up the same page, therefore, we need to bypass this mechanism by adding random parameters to the pop-up aspx page. The above modal window code can be changed to the following to avoid this problem:

Public string ModalWindow (string openAspxPage, int width, int height)
{
String js = string. format ("javascript: window. showModalDialog (\ "{0} & rand =" + new Random (). next (). toString () + "\", window, \ "status: false; dialogWidth: {1} px; dialogHeight: {2} px \") ", openAspxPage, width, height );
Return js;
}

Note that the red parameter is a custom parameter, which should be the only change name in the entire project, it is meaningless (The safest way is to name the change as a name such as lakjsdflawdfqwoifa ).
There is another simple method: Add Response. Expires =-1.
Basically, when the above conditions are met, the operation of the modal window is relatively simple during page creation.
If you want to make it easier, you can write the ModalWindow method better. Because the time is tight, the things here are rough. When you are free, modify it, improve the Function class content, and add some common JavaScript code to make it configurable.
By the way, when you are free, you should change the JavaScript code that comes with software such as "audio and color", and re-create a specialized JavaScript special effect. net class library.

 

Note: A New Page is opened through window. open, and a parent-child relationship exists before the two pages. The child page can access the parent page through opener (controls and js functions written in the parent page), and the parent page can also access the child page through sub. For example, if there is a js function sayhello () on the parent page, you only need opener. sayhello () on the subpage to call it.

 

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/lne818/archive/2008/07/29/2731478.aspx

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.