views:

20

answers:

1

I'm working with a GridView in an UpdatePanel and perform databinding to an ObjectDataSource using the DataSourceID property. Everything works just fine except for when I perform data validation in the object source and return false from the Update. I use this to set the content and visibility of another control in the GridView. However, this never shows up since the GridView performs a hidden DataBind() in OnPreRender() even though EnableViewState = "true" (via the BaseDataBoundControl).

Is there an easy way to just turn this extraneous DataBind() off? I've used reflection to set the _requiresDataBind field in BaseDataBoundControl to false and all works as I'd like it to work, but this is hardly a production-worthy approach. Is subclassing GridView the only way? Am I just missing something?

A: 

Apparently there is no way around this if you don't databind the grid. I ended up subclassing the GridView, adding a Boolean property called "CancelDataBind", and overriding the method called EnsureDataBind() and adding logic to test the CancelDataBind property before calling the base implementation. This worked out well.

codekaizen