【发布时间】:2009-03-16 17:07:40
【问题描述】:
我在代码隐藏中使用带有 GridView 的 ObjectDataSource 和 OnObjectCreated 处理程序。如果我以编程方式更改 GridView 上的子控件值,则整个控件在同一请求中第二次获得数据绑定(如 OnObjectCreated 处理程序所示),这是我不想要的。这发生在初始页面 GET 请求上(因此它不是回发问题)。这是跟踪显示的内容:
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
即使我操纵子控件,有没有办法防止第二轮数据绑定?数据层中没有任何变化,因此不需要。另请注意,没有涉及似乎也会导致双重数据绑定的图像 url。谢谢。
更新:
我不确定这是否有帮助,但查看调用 OnObjectCreated 处理程序时的堆栈跟踪会发现以下差异:
第一个事件处理程序调用:
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
第二个事件处理程序调用:
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
同样,这一切都来自最初的 GET 请求。任何想法为什么它被调用两次?
【问题讨论】:
标签: asp.net data-binding gridview