Processing updates after submitting a form

What is the best way to prevent the form from being resubmitted when updating? !IsPostBack does not process updates. I tried using a bool variable that sets to true on initial submission, but it seems to be reset every time the page loads.

I read a little about cookies, but I'm not sure how to set them to move between pages.

My setup:

  • Default.aspx (& Default.aspx.cs)
  • Results.aspx (& Results.aspx.cs)

I set cookies in web.config file as SessionState? Is there anything better to use than cookies?

+2
source share
4 answers

since I think you could look at the Post / redirect / Pattern PRG template from Wikipedia

An HTTP 303 response code was introduced in the HTTP 1.1 specification to ensure that in this situation the web browser browser can safely update the server response without triggering the initial HTTP POST request for resending.

It simply consists of redirecting after a successful publication, so updating the user results in an idempotent GET, not a POST. It has the added benefit that the browser forgets about POST in its history, which means that the back button will not be sent either.

even you can check before sending data with your database, regardless of whether the data exists or not based on the primary key or unique identifier.

but you check this PRG template, it may help you.

Redirecting responses. in asp.net

+6
source

It is best to assign a unique identifier to the form (put it in a hidden form variable). When the form submits, you keep track of whether the identifier was previously used. If not, you allow the sending to continue, otherwise you will reject it.

Edit: It should be clear to me that you really need a database to do this correctly. You can try to pay back something with cookies, but this is not proof of a fool, since the user can disable cookies in his browser.

+2
source

set a goal in the form, and when you click the "Submit" button, it will go to the landing page. do what has ever been processed on this page, and do a redirect to the results page. this may be the page you used to submit. Updating the results page will not be resubmitted.

+1
source

I do not feel anything better than the below links for this scenario.

http://www.codeproject.com/Articles/18841/Refresh-Module

+1
source

Source: https://habr.com/ru/post/1400555/


All Articles