Asp.net page refresh

Source: Internet
Author: User

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

First:

C # code
   private void Button1_Click( object sender, System.EventArgs e ) {   Response.Redirect( Request.Url.ToString( ) ); } 

Second:

C # code
   private void Button2_Click( object sender, System.EventArgs e ) { Response.Write( " < script language=javascript>window.location.href=document.URL; < /script>" ); } 

Third:

C # code
   private void Button3_Click( object sender, System.EventArgs e ) { Response.AddHeader( "Refresh","0" ); } 

Fourth:

C # code
   Private void button6_click (Object sender, system. eventargs e) {// does it seem wrong? // Response. Write ("<script language = JavaScript> window. Location. Reload (); </SCRIPT> ");}

Fifth:

HTML code
   <SCRIPT> <! -- Var Limit = "3:00" If (document. images) {var parselimit = limit. split (":") parselimit = parselimit [0] * 60 + parselimit [1] * 1} function beginrefresh () {If (! Document. images) returnif (parselimit = 1) window. location. reload () else {parselimit-= 1 curmin = math. floor (parselimit/60) cursec = parselimit % 60if (curmin! = 0) curtime = curmin + "Minute" + cursec + "second to refresh this page! "Elsecurtime = cursec +" refresh this page in seconds! "Window. status = curtimesettimeout ("beginrefresh ()", 1000)} window. onload = beginrefresh // --> </SCRIPT> <Div style = "Z-INDEX: 102; left: 408px; position: absolute; top: 232px "ms_positioning =" text2d "> <p> <font size =" 3 "> automatically refresh the page </font> </P> </div>

Sixth:
<Meta http-equiv = "refresh" content = "300; url1_target.html"> 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 ("<SCRIPT> alert ('Congratulations, registration successful! '); </SCRIPT> "); response. redirect ("main.html"); at this time, when the prompt content does not come out, it jumps, and response. redirect ("main.html"); no difference.

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

Response. Write ("<script language = JavaScript> alert ('Congratulations, registration successful! ') </SCRIPT> "); response. write ("<script language = JavaScript> commandid location.href+'main.html '</SCRIPT>"); this meets our requirements and redirects to the page after the prompt.

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 ("<script language = JavaScript> alert ('Congratulations, registration successful! ') </SCRIPT> "); response. write ("<script language = JavaScript> using your parent.frameleft.location.href+'main.html '</SCRIPT>"); ASP. NET page Refresh: summary of the implementation methods of automatic page Refresh:

1)

<Meta http-equiv = "refresh" content = "10; url = redirected page"> 10 indicates refreshing every 10 seconds

2)

<Script language = ''javascript ''> window. location. reload (true); </SCRIPT> if you want to refresh an IFRAME, replace the window with the frame name or ID.

3)

<Script language = ''javascript ''> window. navigate (" URL on this page "); </SCRIPT> 4>

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

Response. Write ("<script language = JavaScript> window. Location. href = Window. Location. href; </SCRIPT>") refresh the parent page:

Response. Write ("<script language = JavaScript> opener. Location. href = opener. Location. href; </SCRIPT>") to the specified page:

Response. Write ("<script language = JavaScript> window. Location. href = 'yourpage. aspx '; </SCRIPT> ")
Summary of page refreshing implementation (HTML, ASP, JS)

'By aloxy

Timed Refresh:

1,

<SCRIPT> setTimeout ("location. href = 'url'", 2000) </SCRIPT> Description: The URL is the URL of the page to be refreshed.

2000 is the waiting time = 2 seconds,

2,

<Meta name = "refresh" content = "N; URL"> description:

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,

<% Response. Redirect URL %> Note: Generally, you can use a URL parameter or a form value to determine whether an operation has occurred and then use response. Redirect to refresh.

4. Refresh the framework page

<Script language = JavaScript> top. leftfrm. Location. Reload (); parent. frmtop. Location. Reload (); </SCRIPT> refresh the page after the pop-up window

Response. write ("<SCRIPT> window. showmodaldialog ('.. /OA/spcl. aspx ', window, 'dialogheight: 300px; dialogwidth: 427px; dialogtop: 200px; dialogleft: 133px') </SCRIPT> "); // open response. write ("<SCRIPT> document. location = document. location; </SCRIPT> "); Add the <base target =" _ Self "/>

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 ("<script language = JavaScript>"); response. write ("parent. left. location. href = 'paydetailmanage _ left. aspx '"); response. write ("</SCRIPT> ");
Implementation of the page timed refresh function

There are three methods:

1. Set in HTML:

<Title> XXXXX </title> and add the following line!

Timed Refresh:

<Meta HTTP-EQUIV = "refresh" content = "10"> 10 represents the refresh interval, in seconds

2. jsp

<% Response. setheader ("refresh", "1"); %> refresh every second

3. Use javascript:

<Script language = "JavaScript"> setTimeout ("self. Location. Reload ();", 1000); <SCRIPT> one second

Automatic page Jump:

1. Set in HTML:

<Title> XXXXX </title> and add the following line!

Timed jump and refresh:

<Meta http-equiv = "refresh" content = "20; url = http: // your own URL">, in which 20 refers to jump to HTTP after 20 seconds: // your own URL page.

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

<Script language = "JavaScript"> <! -- Function clock () {I = I-1 document. Title = "this window will be automatically closed after" + I + "seconds! & Quot; if (I> 0) setTimeout (& quot; clock (); & quot;, 1000); else self. close () ;}var I = 2 clock (); // --> </SCRIPT> // The second function that refreshes the parent page

<Script language = "JavaScript"> opener. Location. Reload (); </SCRIPT> // The third open window.

<Script language = "JavaScript"> function show (mylink, mytitle, width, height) {mailwin = Window. open (mylink, mytitle, 'top = 350, Left = 460, width = '+ width +', Height = '+ height +', scrollbars = no ')} </SCRIPT> these methods can be used to refresh the Asp.net page.

Related Article

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.