This article introduces page refresh. It not only introduces how to implement page refresh in asp.net, but also introduces jsp and js to implement page refresh and framework refresh, if you need it, you can refer to.
Let's take a look at the implementation of ASP. NET page refreshing:
First:
The Code is as follows: |
Copy code |
C # code Private void button#click (object sender, System. EventArgs e) { Response. Redirect (Request. Url. ToString ()); } |
Second:
C # code
The Code is as follows: |
Copy code |
Private void Button2_Click (object sender, System. EventArgs e) { Response. Write ("<script language = javascript> window. location. href = document. URL; </script> "); } |
Third:
C # code
The Code is as follows: |
Copy code |
Private void Button3_Click (object sender, System. EventArgs e) { Response. AddHeader ("Refresh", "0 "); } |
Fourth:
C # code
The Code is as follows: |
Copy 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
The Code is as follows: |
Copy 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:
The Code is as follows: |
Copy code |
<Meta http-equiv = "refresh" content = "300; url?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:
The Code is as follows: |
Copy code |
Response. Write ("<script> alert ('Congratulations, registration successful! '); </Script> "); Response. Redirect ("main.html "); |
At this time, if the prompt content does not come out, we will jump to, and
The Code is as follows: |
Copy code |
Response. Redirect ("main.html "); |
There is no difference.
In this case, we use the following code to test ASP. NET page Refresh:
The Code is as follows: |
Copy code |
Response. Write ("<script language = javascript> alert ('Congratulations, registration successful! ') </Script> "); Response. Write ("<script language = javascript> commandid location.href+'main.html '</script> "); |
This allows us to jump 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:
The Code is as follows: |
Copy code |
Response. Write ("<script language = javascript> alert ('Congratulations, registration successful! ') </Script> "); Response. Write ("<script language = javascript> Response parent.frameleft.location.href+'main.html '</script> "); |
ASP. NET page Refresh: summary of the implementation methods of automatic page Refresh:
1)
The Code is as follows: |
Copy code |
<Meta http-equiv = "refresh" content = "10; url = redirected page"> |
10 indicates refreshing every 10 seconds.
2)
The Code is as follows: |
Copy code |
<Script language = ''javascript ''> window. location. reload (true); </script> |
If you need to refresh an iframe, replace the window with the frame name or ID.
3)
The Code is as follows: |
Copy code |
<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,
The Code is as follows: |
Copy code |
<Script> setTimeout ("location. href = 'url'", 2000) </script> |
Note: The url is the URL of the page to be refreshed.
2000 is the waiting time = 2 seconds,
2,
The Code is as follows: |
Copy code |
<Meta name = "Refresh" content = "n; url"> |
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,
The Code is as follows: |
Copy code |
<% Response. redirect url %> |
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
The Code is as follows: |
Copy code |
<Script language = javascript> top. leftFrm. location. reload (); parent. frmTop. location. reload (); </script> 〉 |
Refresh after the window pops up
The Code is as follows: |
Copy code |
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 left half of the Framework page
The Code is as follows: |
Copy code |
Response. 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:
The Code is as follows: |
Copy code |
<META HTTP-EQUIV = "Refresh" content = "10"> |
10 indicates the refresh interval, in seconds.
2. jsp
The Code is as follows: |
Copy code |
<% Response. setHeader ("refresh", "1"); %> |
Refresh Every second
3. Use javascript:
The Code is as follows: |
Copy code |
<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:
The Code is as follows: |
Copy code |
<Meta http-equiv = "refresh" content = "20; url = http: // your own URL">, |
Among them, 20 refers to jump to the http: // own URL page every 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
The Code is as follows: |
Copy code |
<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.