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?
I'm not using AJAX. I'm not completely sure how the second operation would be re-fired. I debugged the javascript that fires the addRow event and it is only called once... So the addRow event doesn't re-fire as I see it.
Are you handling the UpdateRow event? Are you handling a server event for the Menu?
It might be that the copy operation is adding the row (causing the add row event to be fired) then copying the values and leaving the row (causing the update row to be fired)
Without being able to see what it is doing, I am really at a loss. If you can reproduce this in a sample, I would submit it to Developer Support for debugging.
Is there a way to do what you want without the AddNew event being wired up? Why are you using that event?