Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gridview RowUpdating event not firing

I have a Gridview with AutoGenerateColumns="False".
I am using a TemplateField to display my Edit, Update and Cancel 'buttons' in the first column of the GridView within respective ItemTemplate and EditItemTemplate fields.

Within the ItemTemplate I have an ImageButtong with a CommandName of "Edit". This works as expected and I can put a breakpoint in the RowCommand event handler to see the "Event" command name. After it has been clicked the postback places that row in edit mode. All textboxes appear as they are meant to.

At this point in time the above EditItemTemplate is displayed with two ImageButtons within it. One has it's CommandName = "Update" and the other "Cancel".

My problem lies in that the click on the Update ImageButton posts back, but neither the RowCommand nor RowUpdating events get triggered.

I have set the requisite attributes in the GridView tag. (Note, in the gridview the EnableViewState="False" - if I set it to True I get the standard

"Failed to load viewstate. The control tree..." etc. error)

One strange thing that I've noticed that makes me think it's a ViewState problem is that if I change the CommandName of the Update button to "Edit" that postback event does get captured in the RowCommand event...

Any suggestions are welcome. Thanks.

like image 267
Sean Avatar asked Dec 01 '22 07:12

Sean


1 Answers

As noted by Asem and Ron, adding the CausesValidation="false" attribute to the CommandField resolved the problem. The reason was that I had some other validation controls on the page and on the GridView update the page was firing the other validation controls, so I think its better to set a ValidationSummary property.

like image 180
Michael Av Avatar answered Dec 04 '22 02:12

Michael Av