Methods for refreshing ASP. NET pages

Source: Internet
Author: User
First look at ASP. NET page refreshing implementation method: 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 ("<script language = JavaScript> window. location. href = document. URL; </SCRIPT> ");} third: Private void button3_click (Object sender, system. eventargs e) {response. addheader ("re Fresh "," 0 ");} Fourth: Private void button6_click (Object sender, system. eventargs e) {// seems wrong? // Response. Write ("<script language = JavaScript> window. Location. Reload (); </SCRIPT>") ;}fifth: <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. when writing an Asp.net program, we often encounter page Jump issues when refreshing another framework page using href. We often use response. redirect, such If the customer wants to use the prompt during the jump, this will not work, for example: 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. Now 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 window. location. the href statement can be used to refresh the page (response. redirect cannot be achieved, 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 automatic page refresh implementation methods: 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 of 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> ") Go to the specified page: response. write ("<script language = JavaScript> window. location. href =' Yourpage. aspx '; </SCRIPT> ") page refresh implementation Summary (HTML, ASP, JS)' By aloxy regular Refresh: 1, <SCRIPT> setTimeout (" location. href = 'url' ", 2000) </SCRIPT> Note: URL is the URL of the page to be refreshed. 2000 is the wait time = 2 seconds, 2, <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, the URL is the URL of the page to be refreshed. 3, <% response. redirect URL %> Description: a URL parameter or form value is generally used to determine whether or not An operation occurs and then refresh with response. Redirect. 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 (! In ispostback), refresh the left side on the right side of the Framework page // refresh the response part on the left side of the Framework page. write ("<script language = JavaScript>"); response. write ("parent. left. location. href = 'paydetailmanage _ left. aspx '"); response. write ("</SCRIPT>"); there are three ways to implement the page regularly refresh function: 1. Set in HTML: <title> XXXXX </title> and add the following line! Scheduled Refresh: <meta HTTP-EQUIV = "refresh" content = "10"> 10 represents the refresh interval, measured 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 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">, 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 and submits data in window B to Window C. At last, refresh window a and close several JavaScript Functions in window B. // the first one is automatically closed. window <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> for questions about Asp.net page refresh, add to favorites Methods are useful.

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.