asp.net formview (using object datasource) postback insert

寵の児 提交于 2019-12-25 03:56:19

问题


I have a formview which using objectdatasource and default mode = insert... but after I inserted item if you refresh page inserting again and again....I tried Is.postback control but couldnt prevent this.Is there anyway to do it ?


回答1:


That is a common fundamental problem, which is a little harder to solve. There are a couple of ways to deal with it. You could use a means to detecting a page refresh, like this:

  • http://www.codeproject.com/Articles/68371/Detecting-Refresh-or-Postback-in-ASP-NET
  • http://www.codeproject.com/Articles/10240/Detecting-Page-Refresh
  • http://www.jaredlog.com/?p=13

This is a server-side approach to responding to events; you could then cancel the insert programmatically. Another option is to check to see if the same data previously posted, and then don't do a double insert. Alternatively, we use the RadAjaxPanel from Telerik (though the UpdatePanel should work the same too) to handle this, as the POST operations are done through AJAX, so when you refresh it refreshes the original GET request.



来源:https://stackoverflow.com/questions/16238456/asp-net-formview-using-object-datasource-postback-insert

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