Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 Page_Unload 中自动发布一个页面。当我写的时候Response.Redirect,我得到了错误。
Response.Redirect
想实现显示数据列表。我正在对其进行数据绑定,但它在刷新页面后显示。
有人可以帮助我吗?
protected void Page_Unload(object sender, EventArgs e) { ... DataList1.DataBind(); //autopostback in this line }
在事件中你不能做这样的Unload事情。
Unload
当Unload事件发生时,页面已经被渲染并发送到浏览器,所以现在做任何事情来改变响应已经太晚了。
此外,从服务器代码进行回发是没有意义的,因为这只会创建一个永恒的循环,而不会将任何内容发送回浏览器。如果您想在浏览器中发生某些事情时进行回发,您可以使用 Javascript 而不是在服务器代码中执行此操作。
使用PreRender事件而不是UnLoad。注意:我知道它的老问题,但我相信有人会使用这个答案。