views:

24

answers:

1

Hi,

I would like to know how to avoid the same operation from being performed twice after some action has been taken on the gridview.

i.e. on clicking a button in gridview, operations in RowCommand get executed. Then on doing a page refresh, the same thing gets done again.

How can we avoid this?

Thanks!

+2  A: 

Could you not just set a flag then check if it's true or not. For example when they press the button the flag is set to false so it executes the commands and sets the flag to true. When they refresh the flag is set to true to it doesn't execute the command.

Could use a hidden label for the flag if needed. Not the nicest solution but it works.

if(flag==false)
{
    //RowCommand Operations
    flag=true;
}

For the label approach just set the initial label text to "" then

if(myLabel.Text=="")
{
     //RowCommand Operations
     myLabel.Text="Something Else";
}
Gage
Thanks mate. If there are ten buttons in the gridview, then I don't think keeping ten flags/labels would be a viable option. Came across this article while googling. http://aspalliance.com/687_Preventing_Duplicate_Record_Insertion_on_Page_Refresh.1 Worth taking a look. Am still thinking though!