How to refresh the page in Asp.net

Source: Internet
Author: User
First, let's take a look at the implementation of ASP. NET page refreshing:

First:

Private void button#click (Object sender, system. eventargs e) {response. Redirect (request. url. tostring ();} second:

Private void button2_click (Object sender, system. eventargs e) {response. Write ("window. Location. href = Document. url;") ;}third:

Private void button3_click (Object sender, system. eventargs e) {response. addheader ("refresh", "0");} Fourth:

Private void button6_click (Object sender, system. eventargs e) {// does it seem wrong? // Response. Write ("window. Location. Reload ();") ;}fifth:

Automatically refresh page 6:

Use window. Location. href to refresh another framework page

When writing the Asp.net program, we often encounter page Jump problems. We often use response. Redirect. If the customer wants to use the prompt during the jump, this will not work, such:

Response. Write ("alert ('congratulations, registration successful! '); "); Response. Redirect (" main.html "); at this time, the prompt content is skipped, and there is no difference with response. Redirect (" main.html.

In this case, we use the following code to test ASP. NET page Refresh:

Response. Write ("alert ('congratulations, registration successful! ') "); Response. Write (" too many location.href}'main.html' "); this achieves our requirements. After the prompt, jump to the page.

The most important thing is that the window. Location. href statement can implement a framework page, refresh the page of another framework after executing the server code (response. Redirect cannot be reached, at least I did not find it ):

For example, the index.htm page has two frameworks: frameleft and frameright. On the frameright page, execute the server code and refresh the page in frameleft.

Previously, the most common issue was to automatically refresh the login box after registration and change the login box to the logged-on page. You only need to add a section after the successfully registered code, that is, you can refresh the page of another framework. The Code is as follows:

Response. Write ("alert ('congratulations, registration successful! ') "); Response. Write (" your own parent.frameleft.location.href='main.html' "); ASP. NET page Refresh: summary of the implementation of automatic page Refresh:

1)

10 indicates refreshing every 10 seconds.

2)

Window. Location. Reload (true); if you want to refresh an IFRAME, replace the window with the frame name or ID number.

3)

Window. navigate ("URL of this page"); 4>

Function ABC () {window. Location. href = "/blog/window. Location. href"; setTimeout ("ABC ()", 10000);} refresh this page:

Response. Write ("window. Location. href = Window. Location. href;") refresh the parent page:

Response. Write ("opener. Location. href = opener. Location. href;") to the specified page:

Response. Write ("window. Location. href = 'yourpage. aspx ';")

Summary of page refreshing implementation (HTML, ASP, JS)

'By aloxy

Timed Refresh:

1,

SetTimeout ("location. href = 'url'", 2000) Description: The URL is the URL of the page to be refreshed.

2000 is the waiting time = 2 seconds,

2,

Note:

N is the number of seconds to wait before loading the specified URL.

URL is an absolute URL to be loaded.

N is the waiting time, in seconds.

URL is the URL of the page to be refreshed

3,

Note: a URL parameter or form value is generally used to determine whether an operation is performed and then refresh with response. Redirect.

4. Refresh the framework page

<Script language = JavaScript> top. leftfrm. location. reload (); parent. frmtop. location. reload (); window. showmodaldialog ('.. /OA/spcl. aspx ', window, 'dialogheight: 300px; dialogwidth: 427px; dialogtop: 200px; dialogleft: 133px') "); // open response. write ("document. location = document. location; "); add it to the Code head of the child form page

Add the refreshed content to If (! Ispostback)

Refresh the left side on the right side of the frame page

// Refresh the response in the left half of the Framework page. write (""); response. write ("parent. left. location. href = 'paydetailmanage _ left. aspx '"); response. write ("");

Implementation of the page timed refresh function

There are three methods:

1. Set in HTML:

Add the following line after XXXXX!

Timed Refresh:

10 indicates the refresh interval, in seconds.

2. jsp

Refresh Every second

3. Use javascript:

SetTimeout ("self. Location. Reload ();", 1000); once a second

Automatic page Jump:

1. Set in HTML:

Add the following line after XXXXX!

Timed jump and refresh:

, 20 indicates that the page jumps to http: // its own URL after 20 seconds.

Click the button to submit the form and refresh the upper-level window.

Window A opens window B

Then, submit data in B to the C window.

Last, refresh window.

And close window B.

Several JavaScript Functions

// The first window is automatically closed

0) setTimeout ("clock ();", 1000); else self. close () ;}var I = 2 clock (); // --> // The second function that refreshes the parent page

Opener. Location. Reload (); // the third window is opened.

Function show (mylink, mytitle, width, height) {mailwin = Window. open (mylink, mytitle, 'top = 350, Left = 460, width = '+ width +', Height = '+ height +', scrollbars = no ')} these methods can be used to refresh the Asp.net page.

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.