I am using an ObjectDataSource with a GridView with an OnObjectCreated handler by code. If I programmatically change the value of a child control in a GridView, the entire control gets data binding a second time in the same query (as shown by the OnObjectCreated handler), which I don't want. This happens in the original request of the GET page (so this is not a postback problem). Here's what the trace shows:
aspx.page Begin PreRender
Custom IN handleDSObjectCreated() => tsDao: ETime.DAL.TimeSheetDAO
Custom OUT handleDSObjectCreated()
Custom IN handleDSObjectCreated() => tsDao: ETime.DAL.TimeSheetDAO
Custom OUT handleDSObjectCreated()
aspx.page End PreRender
Is there a way to prevent the second round of data binding, even if I control child controls? Nothing in the data layer changes, so it is not required. Please note that there are also no links to images that seem to also cause double data binding. Thanks.
Update:
I'm not sure if this helps or not, but when viewing the stack trace at the moment the OnObjectCreated handler is called, the following differences are displayed:
Calling the handler of the first event:
System.Web.dll!System.Web.UI.WebControls.GridView.DataBind() + 0x5 bytes
System.Web.dll!System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() + 0x53 bytes
System.Web.dll!System.Web.UI.WebControls.GridView.OnPreRender(System.EventArgs e = {System.EventArgs}) + 0x19 bytes
System.Web.dll!System.Web.UI.Control.PreRenderRecursiveInternal() + 0x57 bytes
Second event handler call:
System.Web.dll!System.Web.UI.WebControls.GridView.DataBind() + 0x5 bytes
System.Web.dll!System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() + 0x53 bytes
System.Web.dll!System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() + 0x46 bytes
System.Web.dll!System.Web.UI.Control.EnsureChildControls() + 0x58 bytes
System.Web.dll!System.Web.UI.Control.PreRenderRecursiveInternal() + 0x33 bytes
Again, this is all from the original GET request. Any ideas why he appears twice?
source
share