AJAX, Postback, and Browser Updates

I created a user control to handle comments on specific business objects such as contacts and clients. Works great ... except for one problem.

I am using a ListView control to edit and delete comments and a separate area on the same user control to add a new comment. All this is wrapped in UpdatePanel.

Screen shot

Here is my scenario ... the user adds a new comment ... the page postbacks, the data is saved successfully, and the ListView control is updated to show the new comment. Now, if the user updates the browser, he, of course, will return back and add one more repeated entry.

Any ideas on how best to prevent this?

+3
source share
2 answers

You can try using the Post / Redirect / Get pattern . Basically, instead of allowing postback to send data, redirect to the page. Thus, if the user is updated, he / she updates the GET command, not the POST command.


Sorry .. missed the UpdatePanel part. Make sure the submit button is also within this UpdatePanel. Updating the page will not affect your AJAX call, but when the button is outside the panel, it performs a regular postback, so you send the add request again.
+4
source

ASP.NET , " " Page.IsPostBack:

if(IsPostBack) {
    //do your data-saving code...
}

MSDN

0

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


All Articles