|
-
May 14th, 2003, 11:15 AM
#1
Thread Starter
Junior Member
Is Page_Load the only thing that happens as a page refreshes?
I am using a DataGrid to add a new row to a database and it works fine. BUT if I hit 'Refresh' on the browser right after I have added it, the app tries to execute the add function again and gives me an error. The same thing happens if I run a delete row function. Everything's fine... unless I hit 'refresh'.
If the commands lie on a button_click event function, why is this happening as if it were on a Page_Load event? I thought the only thing that ran as a page reloaded was the Page_Load event. (?)
-
May 14th, 2003, 11:50 AM
#2
I believe the click event basically just causes a page refresh, so the actions are sort of queued in a way and get called again in the refresh the user causes. I think you can set the cache back to nothing or something of the sort to keep this from happening.
-
May 14th, 2003, 12:10 PM
#3
Lively Member
In your Page_Load event.
put your code in if not ispostback then block
i.e
private sub Page_Load (...)
if not IsPostBack() Then
''' Place your code in this here
end if
End Sub
the working of asp.net is such that it post's it's page to itself and this happens on every resfresh as it is server side coding it is stateless so...
-
May 14th, 2003, 12:36 PM
#4
Thread Starter
Junior Member
Well, I do have the if-not-postback loop going on in the page_load event for a datagrid.databind... it's not that... it seems to be something else. Maybe the cache is an issue... I'll try that out. In the meantime, any other ideas?
-
May 14th, 2003, 01:24 PM
#5
Hyperactive Member
IsPostBack only works if the postback event comes from the page itself.
Isn't refreshing from the browser essentially the same as loading it for the 1st time.
-
May 14th, 2003, 02:43 PM
#6
Thread Starter
Junior Member
Yes, or at least thats what i thought. Every time I hit 'refresh' the page attempts to re-execute the last thing I did on it. If I deleted and then refresh, I get an 'index does not exist' error. If I try to add and then refresh, I get a 'duplicate primary key' error. When did 'refresh' ever stop being just relaod as if it were the first time?
-
May 14th, 2003, 03:12 PM
#7
PowerPoster
You can do some type of work around maybe, like on the page load, put the pages address in a session variable, but before that, put a check in to see if the session variable exists, and if so, is it the same page as it is now. This will tell you if the page is the same page as last time, and not to perform those functions again.
-
May 14th, 2003, 11:00 PM
#8
Hyperactive Member
The problem isn't really directly related to asp.net. It's simply the way that html forms work regardless of the technology. If you have a form(just a plain ol' form no .NET or anything) and submit it, and then click refresh, the browser will repeat the last thing you did(after asking whether you want to or not). To prevent probs i'd try to either "redirect" the user to another page that confirms what they just did, then by refreshing they won't end up resubmitting(since the last action was a redirect). Or, if after submitting they come back to the same page, make sure to check if that persons info already exists in the database, if so let 'em know with a message that their info is already in the database and cannot be added again or whatever.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|