ObjectDataSource 触发两次,或单独触发 [英] ObjectDataSource firing twice, or on its own

查看:23
本文介绍了ObjectDataSource 触发两次,或单独触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以准确解释 ObjectDataSource 是如何/何时触发的吗?我有一个 ASP.NET 页面,带有一个引用 ODS 的 GridView.我在 ODS 使用的方法中放置了一个断点,并注意到它触发了两次.

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();
      }
    }

其中 MethodA 和 MethodB 最终都调用了 gv.DataBind().这是有道理的,因为我假设每次调用 GridView.DataBind() 都会导致向 ODS 询问数据,从而运行我的数据访问方法.

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.

奇怪的是,当注释掉对 MethodA 的调用时,它仍然会触发两次.检查调用堆栈显示该方法首先作为 MethodB 的结果运行,然后再次运行,除了 [外部代码] 之外没有任何痕迹.当我让 MethodA 和 MethodB 都执行时,这种神秘的加载不会发生.

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.

知道这里发生了什么吗?知道我可能有什么其他代码要求 ODS 提供数据吗?我开始认为所有这些无代码"数据控件都比它们的价值更令人困惑和废话.

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.

推荐答案

当我们在代码中动态隐藏/显示 gridview 列时,我遇到了这个问题.

I've experienced this problem when we were hiding/showing gridview column dynamically in code.

这是一个讨论可能导致多选的一些问题的页面http://forums.asp.net/t/1161164.aspx

Here is a page that talks about some issues that might cause multiple Selects http://forums.asp.net/t/1161164.aspx

这篇关于ObjectDataSource 触发两次,或单独触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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