Post-back problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a simple .aspx page where user enters data (e.g Name address,
etc). At the end, he/she clicks Save button which Posts to the same page and
in the Save button's click event I am saving the data into Database. Now
after saving the details the same page gets rendered to the user. If the user
refreshes the browser as its a post - back page the server is trying to store
the values again. what are the different possible ways to avoid this.
Thanks,
Ravi
 
Ravi said:
Hi,
I have a simple .aspx page where user enters data (e.g Name address,
etc). At the end, he/she clicks Save button which Posts to the same page and
in the Save button's click event I am saving the data into Database. Now
after saving the details the same page gets rendered to the user. If the user
refreshes the browser as its a post - back page the server is trying to store
the values again. what are the different possible ways to avoid this.

You can check if the page's code is run after a postback, with
Page.IsPostback.

FB


--
 
Hi,
The problem exists even if I check Page.IsPostBack.
The following steps explains (I hope) my problem:
1)User clicks on a hyperlink.(The entry page loads ) so Page.IsPostBack is
False.
2)User enters values in respective textbox and clicks Save button. The page
posts back. Page.IsPostBack is true. Then it executes the Save
method.(Onclick event of the Save button) and finally renders the page.
3)User refreshes the browser. Now, again Page.IsPostBAck=true and the Save
method also gets executed.(The server thinks user has clicked the Save
button, but actually he has just refreshed the page).
Hope this explains the problem. I am sure everbody wouild have faced this. I
just need various techniques available to avoid this.
Thanks,
Ravi
 
We handle this by creating a hidden field that is loaded with a new GUID
every time a page is generated. We use a Session variable to track the
GUIDs of any pages that update the database. Before we do any updates we
check to make sure that the page GUID is not already in the Session updated
guid list , if its not there we add it and do the updates , if it is there
we either simply ignore the update or send back some type of 'duplicate
transaction' message.
 
Back
Top