最后一个动作事件获得后退点击 [英] Last Action Event get Fired on back Click

查看:80
本文介绍了最后一个动作事件获得后退点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个表格,其中包含:

类别TextBox

按钮将TextBox值保存在数据库中。



代码工作正常,所有文本框值在保存按钮上成功保存点击。



问题:

保存后我重定向到同一页面,现在我在这里点击某个链接假设'Google.Com'然后如果我点击后退按钮浏览器会将我重定向到上一页我的应用程序。 点击后退按钮发现Postback值为True,再次保存按钮事件被触发。



我不想要事件必须在后面单击时被触发,并且文本框值再次保存在数据库中

我该怎么办?



请帮助我,我遇到问题而没有得到解决方案。

Hi,
I have a Form which contains :
Category TextBox
Button to Save the TextBox value in database.

The code works fine, all textbox value get Saved successfully on Save Button Click.

Problem:
After Saving I redirect to same page, and now here when I click on some link suppose 'Google.Com' and then if I click back button the browser redirect me to previous page on my application. on Click on Back Button the Postback value is found to be True, and again Save Button Event gets Fired.

I don't want the event must get fired on back click and again textbox value gets saved in database.
What should I do?

Please help me , I m getting issue and not getting solution on it.

推荐答案

来自其他网站的GOT解决方案



您需要做的是在您的应用中实施发布/重定向/获取(PRG)模式。基本规则是你的POST不应该返回页面(或视图);相反,它应该只返回一个重定向请求,它将获取要显示的页面/视图。



虽然你会发现有关ASP的PRG的更多信息.NET MVC,我假设您正在使用Web表单 - 所以我熟悉的示例并不多。



但概念非常直截了当。 POST后,只需将Response.Redirect返回到要显示的页面即可。它可能看起来像是重复的工作,但你可以节省你所描述的问题。
GOT SOLUTION FROM Other SITE

What you need to do is to implement a Post/Redirect/Get (PRG) pattern in your app. The basic rule is that your POST should not return a page (or a view); instead, it should return just a redirect request that will GET the page/view to show.

While you'll find a lot more information about PRG in relation to ASP.NET MVC, I'm assuming your working with web forms - so there's not much in terms of examples out there that I'm familiar with.

But the concept is pretty straight-forward. After your POST, just return a Response.Redirect back to the page that you want to display. It may seem like duplicate work, but you'll save yourself the problems that you're describing.


将你的插入代码放入if(!ispostback){}
Put your insert code in if(!ispostback) {}


这篇关于最后一个动作事件获得后退点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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