How do I refresh the page in ASP.NET? (Let it reload itself by code)

后端 未结 14 1843
悲&欢浪女
悲&欢浪女 2020-11-28 02:12

How do I refresh a page in ASP.NET? (Let it reload itself by code)

I\'d rather not use Response.Redirect() because I don\'t know if the page I will be on, as it\'s i

相关标签:
14条回答
  • 2020-11-28 02:23

    You can use 2 ways for solve this problem: 1) After the head tag

    <head> 
    <meta http-equiv="refresh" content="600">
    </head>
    

    2) If your page hasn't head tag you must use Javascript to implement

    <script type="text/javascript">
      function RefreshPage()
      {
        window.location.reload()
      }
    </script>
    

    My contact:

    http://gola.vn

    0 讨论(0)
  • 2020-11-28 02:24

    The only correct way that I could do page refresh was through JavaScript, many of top .NET answers failed for me.

    Response.Write("<script type='text/javascript'> setTimeout('location.reload(true); ', timeout);</script>");
    

    Put the above code in button click event or anywhere you want to force page refresh.

    0 讨论(0)
  • 2020-11-28 02:31

    If you don't want to do a full page refresh, then how about wrapping what you want to refresh inside of a UpdatePanel and then do an asynchronous postback?

    0 讨论(0)
  • 2020-11-28 02:38

    In my user controls, after updating data I do:

      Response.Redirect(Request.RawUrl);    
    

    That ensures that the page is reloaded, and it works fine from a user control. You use RawURL and not Request.Url.AbsoluteUri to preserve any GET parameters that may be included in the request.

    You probably don't want to use: __doPostBack, since many aspx pages behave differently when doing a postback.

    0 讨论(0)
  • 2020-11-28 02:40

    Use javascript's location.reload() method.

    <script type="text/javascript">
      function reloadPage()
      {
        window.location.reload()
      }
    </script>
    
    0 讨论(0)
  • 2020-11-28 02:40

    for asp.net core 3.1

    Response.Headers.Add("Refresh", "2");// in secound
    

    and

    Response.Headers.Remove("Refresh");
    
    0 讨论(0)
提交回复
热议问题