ObjectDataSource firing twice, or on its own

Posted by LoveMeSomeCode on Stack Overflow See other posts from Stack Overflow or by LoveMeSomeCode
Published on 2010-04-14T21:24:06Z Indexed on 2010/04/14 22:03 UTC
Read the original article Hit count: 150

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about databinding