Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

F5 causes Button click to fire - how can I prevent?

Status
Not open for further replies.

R7Dave

Programmer
Oct 31, 2007
181
US
Hello

I have a button on a page that inserts a record into a SQL database. The value from a textbox is inserted into a field and then the field is cleared.

After I do this, if I press F5 to refresh - the records is inserted again - I stepped through the code, it does the Page_Load then goes to the Button event

In the Button event, the TextBox.Text ="" after the record is inserted, also I have this IF....
If Trim(TextBox.Text) <> "" Then
' Insert Record

but TextBox.Text still holds the value from the previous page load - so I get the same record inserted

Is there a property on the button I can change? I don't understand why this code is being launched - am I missing a basic principle of postbacks?

I need the code in the button not to fire when the user hits F5 - and why it would and keep the old textbox value.

Thanks in advance
Dave
(VS 2005 ASP.NET)
 
why would the user press F5? Your page should be refreshing the data for the user.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Why would the user need to hit F5? This is the proper behavior of the page when you refresh. If you hit F5 or the refresh button in the toolbar, the same thing will happen. In IE, it will give you a pop up message stating that the information will be resent.
 
Hello

My page does refresh the data for the user.

So now, the behavior is, the user submits a record and the page is refreshed with the data they entered and a blank textbox - if they hit F5, a dupe record is entered.

Is this avoidable? I am using IE but I don't receive the message - is there a preference that can be set to have this mesage pop up?

Thanks
Dave
 
yes, don't press f5, there is no reason too.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top