473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Post-back problem

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
Nov 17 '05 #1
3 1681
Ravi wrote:
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
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #2
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

"Frans Bouma [C# MVP]" wrote:
Ravi wrote:
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
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Nov 17 '05 #3
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.

"Ravi" <Ra**@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
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

"Frans Bouma [C# MVP]" wrote:
Ravi wrote:
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
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Spud | last post by:
<?php // pullpage function by Nick bouton http://www.nickbouton.com/. $CustomerID = "IDHERE"; $method = "POST"; $host = "xml.mydata.com"; $usepath = "/xml.asp"; //print all vars in an...
1
by: Alec | last post by:
Hi All, I have recently built a site using PHP and MySQL, and started to implement a basic forum into it. However, the form to post messages doesnt do what I want it to. If there is no user...
2
by: Erik Johnson | last post by:
I am trying to work with a program that is trying make an HTTP POST of text data without any named form parameter. (I don't know - is that a normal thing to do?) I need to write a CGI program that...
15
by: Thomas Scheiderich | last post by:
I am trying to understand Session variables and ran into a question on how they work with data that is passed. I have an HTM file that calls an ASP file and sends the name either by GET or POST....
2
by: Keith Selbee | last post by:
I am trying to submit data to a webpage in the form of a post and my code is below. It is a function that takes a url and the post content as strings and then performs the post. But as soon as I...
9
by: c676228 | last post by:
Hi, I am new to this discussion forum. I started to post questions on this forum since this Jan. and got many good responses and I am very appreciated to those who are willing to help with their...
6
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out...
10
by: Peter Michaux | last post by:
Hi, All Ajax libraries I've read use encodeURIComponent() on the name- value pairs extracted from forms before POST ing the result to the server with and xmlhttprequest. I can understand why...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
9
by: CindyH | last post by:
Hi Trying to get this code to work for http xml post. I need the post to be xml (doc.outerxml) sent in single key name as stream. The following is the post code and code for receiving the request....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.