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!

Refreshing keeps adding to Database!

Status
Not open for further replies.

KenniM

Programmer
Nov 27, 2002
25
0
0
DK
Thank you for taking your time to look at this post! :D

I have a page with a list of data comming from a database. On the same page one can add a new row to that list!

When hitting "add new row to list" button the page does a postback calling a method in it's codebehind that adds the row to the table in the database! No problem so far!

If I however click the refresh button after doing the above it adds the same row once more. I DO know why it does this but is there a smart way to get arround it? I'm thinking that the back button will cause the same problem!
_________________

Another thought is if I should post my data to another page that handles the database update. And then after updating redirect to the first page! That way I will get arround it - but is this a good way!
__________________

Comments, links, help anyone!
Cheers Kenni


 
Could you post some of your code? so we can look where things actually are?
 
Heres the code for the Codebehind file! When I hit my add row button on page it is handled by "btnSubmitTask_Click". No Problem. But it's the refresh/update in browser part that's triggy since it'll keep calling the handler adding the same row.

I have found other posts about this problem, but non have been of help to me so far! :D

using System;
using System.Data.OleDb;
using System.Web.UI;
using System.Web.UI.WebControls;
using TaskManagerData;

public class Tasklist : Page {

public TextBox TextBox_Subject;
public PlaceHolder myPlaceHolder = new PlaceHolder();

void Page_Load(Object sender, EventArgs e) {
if (!IsPostBack) {
InsertTasklist();
}
}

public void btnSubmitTask_Click(object sender, ImageClickEventArgs e){
UpdateQuery objUpdateQuery = new UpdateQuery("INSERT INTO TaskList(TaskList_Subject, TaskList_User_ID) VALUES('" + TextBox_Subject.Text + "', 1)");
TextBox_Subject.Text = "";
InsertTasklist();
}


public void InsertTasklist(){
Control ctlTasklist = Page.LoadControl("_Tasklist.ascx");
myPlaceHolder.Controls.Add(ctlTasklist);
}
}
 
If anyone can help It would really be great! Links, post anything to guide me here! :D

Thanks!
Kenni
 
since you said "post anything", well then... :)

it's not the problem with your code. I had the same problem before. what I had was an input page and a submit button. everytime the refresh button is clicked, the focus goes to the submit button and the inputs are added to the database. so what I did was to create another button (lucky for me, my application needed this button) above my submit button, so when the page is refreshed, the focus is on this button, not the submit button, and then everything is well.
I guess what you can do is to write a javascript to move the focus away from your button when the page is refreshed...
 
Thank you jn03! I tried changing the focus away from the submit button, but it didn't fix my problem. :D

I'm not sure it's a matter of focus in my case it's just a question of somehow telling the browser or keeping the browser from resending the information when someone clicks "Refresh" in the browser menu!

It comes up with the following alert - "The page cannot be refreshed without resending the information - Ok / Cancel" you know it.

I think I'm gonna go for another solution to this problem. I'll simply post my form to another aspx that handles the update and then when finished I'm gonna redirect it back. I'm sure that'll fix it.

I just had an idea that keeping everything related to the aspx in it's codebehind would keep things cleaner - reducing the amount of files!

Still, if anyone can help! :D
Cheers Kenni

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top