1

I am performing database update call by clicking on a button which resides on a gridview. It works fine it updates the database properly but the problem is that when i refresh the page it again perform the same operation(db update) i.e again call the RowCommand Event of Gridview.

Here is my short code view:

protected void gridview_RowCommand(object sender, GridViewCommandEventArgs e)
        {   
            if (e.CommandName == "lnkBtn1")
            {
                 userDetails obj=new userDetails();
                 bool flag=obj.Updatuser();
                 if (flag)
                 {
                    lblSucess.Visible = true;

                  //this will binds updated table to grid 
                    this.BindGrid();
                 }
                  else
                 {
                 lblError.visible=true;
                 }
            }
       }
stephen.vakil
  • 3,492
  • 1
  • 18
  • 23
Frank James
  • 157
  • 2
  • 5
  • 15

3 Answers3

1

There seems to be a bug, there is the work around

http://connect.microsoft.com/VisualStudio/feedback/details/102115/gridview-rowcommand-event-firing-twice

Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42
0

It seems that, grid bind function is called each time page is loaded....

  • yes gridbind call at each page load,but RowCommand is want to be call at only buttonclick instead it call twice. – Frank James Jun 06 '12 at 13:39
0

I was having the same problem. I solved it by using OnClick event of the Button inside gridview instead of RowCommand.

Visit below link: GridView RowCommand Event is firing twice in UpdatePanel

Community
  • 1
  • 1
Usman Khalid
  • 3,032
  • 9
  • 41
  • 66