Summary of implementation methods of ASP. NET page refreshing, and asp.net page refreshing
First, let's take a look at the implementation of ASP. NET page refreshing:
First:
C # code
- Private void button#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 (":") parselimitparselimit = 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.
How to refresh the page in ASPNET c #
What is the relationship between your socket communication and web pages? Are they independent of each other?
Which of the following methods can be used to refresh an aspnet page?
There are three methods for page redirection:
1. Response. Redirect ("Url ");
2. Server. Transfer ("URL ");
3. Server. Excute ("URL ")
Server. Transfer ("URL") has three advantages compared with the most common Response. redirdbms ("URL ").
Advantages:
1. It is directly redirected on the server side and does not need to communicate with the browser before redirecting like response. Redirect, which is highly efficient.
2. It can pass the submission value of the previous page. For example, if the value of page A is submitted to page B, and the value of page B is transferred to Page C, Page C can also receive the value submitted by page.
3. You can hide URLs.
Disadvantages: (Modified from)
You cannot refresh the page. For example, If logon information is submitted to page B on page A and Transfer is sent to page A after page B is processed, page A cannot be refreshed, and the specified page does not expire. If pages A and B are not in the same directory, we will find more unexpected results. The images and hyperlinks with relative links have all changed, this is because page B reads the content of page A but outputs it as page B, so the path is changed.
There are four page navigation methods in asp.net. How do I select one for your page?
· If you want users to decide when to convert a page and which page to go to, hyperlink is the most suitable.
· If you want to use a program to control the conversion target, but the conversion time is determined by the user, use the HyperLink control of the Web server to dynamically set its NavigateUrl attribute.
· If you want to connect a user to resources on another server, use Response. Redirect.
· Use Response. Redirect to connect users to non-ASPX resources, such as HTML pages.
· If you want to retain the query string as part of the URL, use Response. Redirect.
· If you want to transfer the execution process to another ASPX page of the same Web Server, you should use Server. transfer instead of Response. redirect, because Server. transfer can avoid unnecessary network communication to achieve better performance and browsing performance.
· If you want to capture the output result of An ASPX page and insert the result to a specific location of another ASPX page, use Server. Execute.
· To ensure that the HTML output is valid, use Response. Redirect instead of Server. Transfer or Server. Execute.
About Server. Execute,
This page navigation method is similar to calling the callback function for the ASPX page. The called page can access the form data and query string set of the calling page, therefore, set the EnableViewStateMac attribute of the called Page command to False.
By default, the output of the called page is appended to the current response stream. However, Server. the Execute method has an overloaded method that allows a TextWriter object (or its sub-object, such as the StringWriter object) to obtain the output of the called page, rather than directly appending it to the output stream, on the original page, you can easily adjust the location of the output result of the called page.
Summary:
Use redirect to redirect a user to a page on another server.
When you need to redirect a user to a non-aspx page, for example, html uses redirect
When the query string needs to be retained to the server as part of the url, because the other two methods cannot achieve two postback operations, the data is first brought back to the server using r ...... remaining full text>