How to force a postback with asp.net and C#

十年热恋 提交于 2019-12-04 06:57:57

Response.Redirect("default.aspx");

(or whatever the name of the current page is)

Response.Redirect() is not the greatest because there is not state. It's a new request. if you want to keep state of all your controls then use the __doPostBack method which is added automatically by ASP when the page is rendered so it's accessible from client side:

you can do this:

or just call it from javascript:

__doPostBack('myElementId','');

Alternatively you can just use javascript code:

document.forms[0].submit();

Response.Redirect(Request.RawURL); 

This also works and you won't need to worry about putting in the path.

Couldn't you just add a javascript block with window.reload() in it?

Here is some useful info on how to do this correctly in Web Forms.

The server can not tell the client to reload.

You can use the html meta refresh:

 <meta http-equiv="refresh" content="2;url=http://the.new.url">

but that will not do a proper post back i think.

Content is how many seconds the client waits to do the refresh.

Do you need a post back to populate a list? Did you look into if solving it with Ajax could help??

Or if you just need a quick and dirty thing, just fake it and fix it later.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!