当控件更改时,ObjectDataSource会创建两次 [英] ObjectDataSource created twice when control is changed

查看:85
本文介绍了当控件更改时,ObjectDataSource会创建两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码隐藏中使用带有OnViewCode处理程序的GridView的ObjectDataSource。如果我以编程方式更改GridView上的子控件值,则整个控件将在同一个请求(如OnObjectCreated处理程序所示)中再次进行数据绑定,这不是我想要的。这发生在初始页面GET请求(因此它不是回发问题)。以下是跟踪显示的内容:

I'm using an ObjectDataSource with a GridView with an OnObjectCreated handler on the code-behind. If I programmatically change a child control value on the GridView, the entire control gets databound a second time in the same request (as shown by the OnObjectCreated handler), which I don't want. This happens on the initial page GET request (so it is not a postback issue). Here's what a 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

即使我操纵子控件,有没有办法防止第二轮数据绑定?数据层中的任何内容都不会变化,因此不需要它。注意也没有涉及的图像url似乎也导致双数据绑定。谢谢。

Is there a way to prevent the second round of databinding even if I manipulate the child controls? Nothing in the data layer changes so it is not needed. Note also there are no image urls involved which seem to cause double databinding too. Thanks.

更新:

我不知道这是否有帮助,但是看着调用OnObjectCreated处理程序点的堆栈跟踪显示以下区别:

I'm not sure if this helps or not, but in looking at the stack trace at the point at which the OnObjectCreated handler is called shows the following differences:

第一个事件处理程序调用:

First Event Handler Invocation:

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 Invocation:

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请求。任何想法为什么被调用两次?

Again, this is all from the initial GET request. Any ideas why it's getting invoked twice?

推荐答案

也许你应该使用

if(!IsPostBack){
 //your code.
}

您正在寻找?

这篇关于当控件更改时,ObjectDataSource会创建两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆