Monday, March 12, 2012

How to handle postback on gridview without mixing records.

I have a griview to list a list of records, on each record, I have set status/delete button, they have commandname/commandargument, once they are clicked, record will be marked or deleted, those actions will not go to a different page.

The problem is when there is a new record added by others when one user click for example "set status" button, when it postbacks one more record is added on top of the list, and then the command will fire on the record above the record the user clicked on since the whole list shifted down since there is a new one added on top.

Any idea how to handle this?

thanks

looks like you disabled the view state. And also check for IsPostback before databinding the gridview.

like

Page_load()

{

if( ! isPostback )

{

GridView.DataBind();

}

}


thanks

right , I disabled viewstate.

If do like you said, how to refresh the gridvew, also, after user click the button, if they click F5, it seems it will fire the click again


oh, since I disable viewstate, I have to databind in every load, right?


but if you databind on every load you will end up in the same problem you mentioned. I would suggest enable view state and databind once you do update or delete functionality.


I see, you suggested me to turn on viewstate. That for sure is a solution.


Page_load()

{

if( ! isPostback )

{

GridView.DataBind();

}

}


Doesn't look like you read the other replies, how does that work without viewstate?

Labels: , , , , , , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home