ObjectDataSource触发两次,或者单独启动 [英] ObjectDataSource firing twice, or on its own
问题描述
我研究了代码,答案似乎很明显。我有
Page_Load()
{
if(!Page.IsPostBack)
{
MethodA();
MethodB();
}
}
其中MethodA和MethodB都最终调用gv.DataBind ()。这是有道理的,因为我假设每次调用GridView.DataBind()将导致向ODS询问数据,因此运行我的数据访问方法。
奇怪的事情是在注释掉对MethodA的调用时,它仍然触发两次。检查调用堆栈会显示方法B的结果首先运行的方法,然后再次显示除[外部代码]之外的任何跟踪。当我让MethodA和MethodB都执行时,这个神秘的负载不会发生。
任何想法这里发生了什么?任何想法我可能有什么其他代码是要求ODS的数据?我开始认为所有这些无代码的数据控件比他们的值得更多的模糊和BS。
当我们在代码中隐藏/显示gridview列时,我遇到了这个问题。
这是一个页面,可以解释一些可能导致多个选择的问题
http://forums.asp.net/t/1161164.aspx
Can someone explain exactly how/when an ObjectDataSource fires? I have an ASP.NET page, with a GridView, which is referencing an ODS. I put a breakpoint in the method the ODS is using, and noticed it was firing twice.
I looked into the code and the answer seemed obvious at first. I had
Page_Load()
{
if(!Page.IsPostBack)
{
MethodA();
MethodB();
}
}
where MethodA and MethodB were both eventually calling gv.DataBind(). This made sense because I assume that each call to GridView.DataBind() would result in asking the ODS for data, and therefore running my data access method.
The weird thing is that when comment out the call to MethodA, it still fires twice. Checking the call stack shows the method being run first as a result of MethodB, and then again, with no trail except [External Code]. This mystery load does not happen when I let MethodA and MethodB both execute.
Any idea what's going on here? Any idea what other code I might have that is asking the ODS for data? I'm starting to think all these 'no code' data controls are more obfuscation and BS than they're worth.
I've experienced this problem when we were hiding/showing gridview column dynamically in code.
Here is a page that talks about some issues that might cause multiple Selects http://forums.asp.net/t/1161164.aspx
这篇关于ObjectDataSource触发两次,或者单独启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!