简体   繁体   中英

How to force a complete page reload (not refresh) in VB.Net

I have a DropDownList that lets the user change the themed stylesheet for a website. It does an autopostback to save the selection to my database. After this saves I want to force a complete page reload (not refresh). So the link to the stylesheet is rebuilt and the form is reset. Is this possible?

I have tried both:

Response.Redirect(Request.Url.AbsoluteUri)
Response.Redirect(Request.RawUrl)

And even tried JavaScript:

window.location.reload();
window.opener.location.href = window.opener.location.href;

but these just seem to cause a refresh. I seek a way that acts as if I clicked in the address bar and pressed [Enter] .

UPDATE

This was a common case of not thinking things through thoroughly. I was attempting to do these actions through an iframe but the parent page was actually the one that set the theme stylesheet. I ended up getting this accomplished by simply:

If IsPostBack() Then
    Dim sb As New StringBuilder()
    sb.Append("<script type=""text/javascript"">")
    sb.Append("window.top.location.reload();")
    sb.Append("</script>")
    ClientScript.RegisterStartupScript(Me.GetType(), "reload", sb.ToString())
End If

Thanks everyone.

您可能想要尝试执行诸如使用版本号进行缓存爆裂之类的操作,该建议在以下内容中出现: 强制浏览器清除缓存

Maybe you can do as you are doing .... but also avoiding cache, adding this meta to your web page:

<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0">
<meta http-equiv="pragma" content="no-cache">

And an old date

<meta http-equiv="expires" content="Sat, 31 Oct 2014 00:00:00 GMT"> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM