asp.net回发 [英] asp.net postback

查看:83
本文介绍了asp.net回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我开发了asp.net页面.
我有一张表格要填写并发送.
单击发送"按钮后返回到客户端,如果客户端按F5
页面处理似乎客户端再次按下发送按钮
我如何才能防止此操作

谢谢

Hi ,

I develop asp.net page.
I have a form to fill and send.
After clcik send button and return to client , if client press F5
the page process seems like client press send button again
how I can prevent from this action

Thanks

推荐答案

我对此有很好的解决方案....

使用将您的网址编码为当前日期时间,然后将该网址添加到会话对象中,例如

Session("update")=Server.URLEncode(System.DateTime.Now.ToString())

添加此会话以查看状态.为此,您可以使用页面pre_render事件

I have good solution for this....

Encode your url to current datetime using and then add this url into session object e.g.

Session("update")=Server.URLEncode(System.DateTime.Now.ToString())

Add this session to view state. For this, you can use page pre_render event

Sub Page_PreRender (sender As Object, e As EventArgs)
    ViewState("update") = Session("update")
End Sub



最后检查此会话以查看状态



and finally check this session to view state

If (Session("update").ToString() == ViewState("update").ToString())
{
//your code for inserting... updating... etc.
}


F5重新加载页面,这意味着它发布了来自上一个操作的数据,该操作是带有回发数据的发布.为了避免这种情况,在处理完数据后,请执行Response.Redirect或Server.Tranfer回到您所在的页面,这会将回发替换为没有回发数据的页面加载.我记得在一个电子商务网站上清楚地做到了这一点,但是我不记得我使用了这两种方法中的哪一种,或者两种方法都奏效,因此请尝试两种方法,肯定会为您做到这一点.
F5 reloads a page, which means it posts the data from the last action, which was the post with the postback data. To avoid this, when you''ve processed the data, do a Response.Redirect or a Server.Tranfer back to the page you are on, this replaces the postback with a load of the page with no postback data. I remember clearly doing this in an ecommerce site, but I don''t recall which of the two I used, or if both work, so try both and one will definitely do it for you.


要使用电子邮件表单,请参阅 php表单教程.也许您的代码有问题.
To work with the email forms look php form tutorial. Perhaps you have something wrong with the code.


这篇关于asp.net回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆