473,386 Members | 1,803 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,386 software developers and data experts.

Clicking Browser refresh is causing records to be inserted multiple times

nateraaaa
663 Expert 512MB
I have an admin application that allows the user to enter information and click a Save button. In the click event of the save button I call an insert stored proc. If the insert proc is successful I then display a javascript pop up telling the user that the record has been added successfully. I then show a datagrid to the user with the record that they just added. My problem is that if I click refresh after successfully adding a record another duplicate record is added. This occurs everytime that I click the browser refresh button. I have tried creating a bool method to determine if the record already exists in the datagrid that I display to the user. This did not work for me. Has anyone else encountered this problem? How can I fix this?

Nathan
Jul 19 '07 #1
4 3275
Plater
7,872 Expert 4TB
Are you using the isPostBack boolean to determine if someone has clicked a button or just hit refresh?
Jul 19 '07 #2
TRScheel
638 Expert 512MB
I have an admin application that allows the user to enter information and click a Save button. In the click event of the save button I call an insert stored proc. If the insert proc is successful I then display a javascript pop up telling the user that the record has been added successfully. I then show a datagrid to the user with the record that they just added. My problem is that if I click refresh after successfully adding a record another duplicate record is added. This occurs everytime that I click the browser refresh button. I have tried creating a bool method to determine if the record already exists in the datagrid that I display to the user. This did not work for me. Has anyone else encountered this problem? How can I fix this?

Nathan
A bool method? Why not a bool session variable? Pseudocode:

if((bool)Session["IsAdded"))
{
Session["IsAdded"] = true;
AddRecord()
}
....

If(readyToAddNewRecord())
Session["IsAdded"] = false;
Jul 19 '07 #3
nateraaaa
663 Expert 512MB
Thank you for the suggestions. I ended up calling a select stored procedure that passed in the username as a parameter. When the browser refresh is clicked the code will run the select stored proc by inserting the username that was entered prior to the page refresh. If no record is found with that username the insert proc will continue; if the user is found the proc will be skipped and I display a message to the user telling them that the user already exists in the database table.

Expand|Select|Wrap|Line Numbers
  1. string branch = txtNewUserBranch.Text;
  2. string IP = txtUserIP.Text;
  3. string[] IParray = IP.Split(new char[] {'.'});
  4. string networkid = IParray[0].ToString() + "." + IParray[1].ToString() + "." + IParray[2].ToString();
  5. string octet4 = IParray[3].ToString();
  6.  
  7. if(!drsql.BrowseData(networkid, Convert.ToInt32(octet4),this.txtNewUser.Text , ref ds))
  8. {
  9. lblMessage.Visible = true;
  10. lblMessage.ForeColor = Color.Red;
  11. lblMessage.Text = "There was a problem loading the data";
  12. }
  13. if(ds.Tables[0].Rows.Count == 0)
  14. {
  15. if(drsql.InsertNewUser(networkid, octet4, octet4, this.txtNewUser.Text.ToString(), branch.ToUpper()))
  16. {
  17. lblMessage.Visible = true;
  18. lblMessage.Text = "<script>alert('New User Added Successfully!');</script>";
  19. this.txtNewUser.Text = "";
  20. this.txtUserIP.Text = "";
  21. this.txtNewUserBranch.Text = "";
  22. pnlUser.Visible = false;
  23. BindData();                    
  24. return;                
  25. }
  26. else
  27. {                        
  28. lblMessage.Visible = true;
  29. lblMessage.ForeColor = Color.Red;
  30. lblMessage.Text = this.txtNewUser.Text + " has already been added to the database";
  31. pnlUser.Visible = false;
  32. this.txtNewUser.Text = "";
  33. this.txtUserIP.Text = "";
  34. this.txtNewUserBranch.Text = "";
  35. return;            
  36. }
Nathan
Jul 19 '07 #4
write:

response.redirect("The same page")

after the save button run the stored procedure so that the refresh button doesnot add the same record twice.
Jul 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. ...
0
by: Alan Johns | last post by:
I have an app with many subforms. Some several levels deep. I find that the deeper I go, the more Access likes to refresh the lower levels multiple times every time the top level form changes once....
5
by: Andrew Chanter | last post by:
I have a situation where I am using an unbound dialog form to update data in an Access 2002 split back end / front end scenario. The data update is done via an ADO call (direct to the back end...
10
by: jaYPee | last post by:
I have a function that call a stored procedure which performs an insert command. now i want to refresh the dataset so that the newly inserted data will be available to my datagrid I have tried...
12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
9
by: Mr Newbie | last post by:
Before someone flames me, I know this is the VB.NET groups, nonetheless, the asp.net guys seems to have almost disapeared from the aspnet groups so I thought I would ask this here. I have a...
2
by: r_o | last post by:
hi i'm new to this issue i'm developping a web application with an access database in my application there's a loop that gets values of a form like: lastElt=request("numberOfItems") for...
10
by: Bill Nguyen | last post by:
I would like to be able to get an active browser window to refresh the URL (reload) every 5 minutes. Is it possible in VB.NET? Thanks Bill
7
by: ebindia0041 | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, Asp.net 1.1 with c# I'm inserting simple records into a table. But one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.