强制回发
有没有办法在代码中强制回发?
我希望强制从我的 asp.net Web 应用程序背后的 C# 代码中的方法引发回发。
Is there a way to force a postback in code?
I'm looking to force the raising of a postback from a method in the c# code behind my asp.net web application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以尝试重定向到同一页面。
You can try redirecting to same page.
表单提交后会触发回发,因此它与客户端操作有关......
看一下这里的解释:
ASP.NET - 是否可以从服务器代码触发回发?
,这里有一个解决方案:
http://forums.asp.net/t/928411.aspx/1
A postback is triggered after a form submission, so it's related to a client action...
take a look here for an explanation:
ASP.NET - Is it possible to trigger a postback from server code?
and here for a solution:
http://forums.asp.net/t/928411.aspx/1
更简单:
Simpler:
这里的解决方案来自 http://forums.asp.net/t/928411.aspx/1 正如 mamoo 所提到的 - 以防网站离线。对我来说效果很好。
Here the solution from http://forums.asp.net/t/928411.aspx/1 as mentioned by mamoo - just in case the website goes offline. Worked well for me.
不,不是来自代码隐藏。回发是使用 Http POST 方法从客户端上的页面发起回服务器上自身的请求。在服务器端,您可以请求重定向,但将是 Http GET 请求。
No, not from code behind. A postback is a request initiated from a page on the client back to itself on the server using the Http POST method. On the server side you can request a redirect but the will be Http GET request.
您可以使用 Repeater 或 ListView 等数据绑定控件,根据需要将其重新绑定到控件属性列表,并让它动态生成控件。
作为替代方案,您可以使用 Response.Redirect(".") 重新加载同一页面。
You can use a data-bound control like the
Repeater
orListView
, re-bind it to a list of control properties as needed, and let it generate the controls dynamically.As an alternative, you can use
Response.Redirect(".")
to re-load the same page.通过使用 Server.Transfer("YourCurrentPage.aspx");我们可以轻松实现这一点,并且它比 Response.Redirect() 更好;因为 Server.Transfer() 将为您节省往返时间。
By using Server.Transfer("YourCurrentPage.aspx"); we can easily acheive this and it is better than Response.Redirect(); coz Server.Transfer() will save you the round trip.
您可以从
Page_Load
事件中手动调用 PostBack 调用的方法:但如果您的意思是可以将
Page.IsPostBack
属性设置为true
如果没有真正的回帖,那么答案是否定的。You can manually call the method invoked by PostBack from the
Page_Load
event:But if you mean if you can have the
Page.IsPostBack
property set totrue
without real post back, then the answer is no.