Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
930
Add row event firing twice
posted

I have a page with two unbound grids which are populated in the code-behind using custom Linq operations. In one of the grids the AddNewRow button visible plus I have a pop-up menu where you can choose to copy a row and insert this copy directly as a new row. I have a single method called "WebGrid_OnAddRow" which is called via the OnAddRow property of the grid on both ocations. It works fine when I use the AddNew button to add an empty row (as it does by default), but if I choose the "copy" function from the pop-up menu, the AddRow event seems to fire twice!

I've debugged the code and it is very weird: the Page_Load method is hit twice and the WebGrid_OnAddRow is too, and it is not always in the same order! I've checked that there is no databinding to the grids in the Page_Load, because I thought this could trigger the double AddRow event, but this was not the case.

If I set the OnAddRowBatch property to handle the AddRow event instead, the function from the pop-up menu works great, but I do not want to use this implementation as the AddNew button doesn't do a post-back and I therefore have to click another button to make the AddNew button take effect (unless of course, I can get the AddNew button to do a post-back?).

Can anyone point me in the right direction of what to look for or do you have any other ideas?

Parents
No Data
Reply
  • 21382
    posted
    Are you using AJAX? It sounds like the menu option is starting an add operation, and, before the first request is done, a second operation is happening and the grid still hasn't finished the first request, so it is refiring.
Children