syn_siju
asked on
Asp.net simple application problem
Hi all
I am deveolping a small application in asp.net. I am having a simple form that stores 3 or 4 data into a database when it is submitted. It works fine . But if we press refresh button of browser, the browser raises a dialog with buttons retry. When retry is clicked, the same data gets stored again.
What could be the reason? The same code for the button click is executed again on refresh.
I am deveolping a small application in asp.net. I am having a simple form that stores 3 or 4 data into a database when it is submitted. It works fine . But if we press refresh button of browser, the browser raises a dialog with buttons retry. When retry is clicked, the same data gets stored again.
What could be the reason? The same code for the button click is executed again on refresh.
A refresh posts the last header and querystring back to the original requestor. After the initial postback (IsPostBack) you can do a response.redirect to the same page. This will make a refresh reload the current page and will not repost the last transaction.
-rca
-rca
if(!IsPostback.Page)
{
Post my data
}
else
{
don't do anything
}
Anderson22 is right. When the page is loaded it calls the page load methd again. If you add in the above code then you can control the post back
Si
{
Post my data
}
else
{
don't do anything
}
Anderson22 is right. When the page is loaded it calls the page load methd again. If you add in the above code then you can control the post back
Si
ASKER
Hi Anderson and Siphilip,
Thanks for ur valuable comments. But I have some problems. Actually the program have the structure like this
----
Page_Load()
{
-----
------
------
}
BtnSave_Click()
{
save the data into the database
}
If i try to redirect the page in Page_Load, I can t get the data saved into the database even for the first time.
I want to execute BtnSave_Click() when the page posts back due to the save button click. If we refresh the page the code for save button click should not execute .
How can we achieve this.
Thanks for ur valuable comments. But I have some problems. Actually the program have the structure like this
----
Page_Load()
{
-----
------
------
}
BtnSave_Click()
{
save the data into the database
}
If i try to redirect the page in Page_Load, I can t get the data saved into the database even for the first time.
I want to execute BtnSave_Click() when the page posts back due to the save button click. If we refresh the page the code for save button click should not execute .
How can we achieve this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Anderson and Siphilip,
Thanks for ur valuable comments. But I have some problems. Actually the program have the structure like this
----
Page_Load()
{
-----
------
------
}
BtnSave_Click()
{
save the data into the database
}
If i try to redirect the page in Page_Load, I can t get the data saved into the database even for the first time.
I want to execute BtnSave_Click() when the page posts back due to the save button click. If we refresh the page the code for save button click should not execute .
How can we achieve this.
Thanks for ur valuable comments. But I have some problems. Actually the program have the structure like this
----
Page_Load()
{
-----
------
------
}
BtnSave_Click()
{
save the data into the database
}
If i try to redirect the page in Page_Load, I can t get the data saved into the database even for the first time.
I want to execute BtnSave_Click() when the page posts back due to the save button click. If we refresh the page the code for save button click should not execute .
How can we achieve this.
ASKER
Hi Anderson,
Thx and it works great.
Regards
Siju
Thx and it works great.
Regards
Siju
When the refresh button is clicked the form data gets submitted to the script again (and it inserts the data again).
A work around is to check the data for duplicates before allowing it to be added. (Generate a unique string for each form and put it in an <input type="hidden"> if duplicates are allowed).