ObjectDataSource runs twice or on its own

Can someone explain how / when the ObjectDataSource is launched? I have an ASP.NET page with a GridView that links to ODS. I set a breakpoint in the method used by ODS and noticed that he shot twice.

I looked at the code, and at first it seemed obvious. I had

    Page_Load()
    {
      if(!Page.IsPostBack)
      {
          MethodA();
          MethodB();
      }
    }

where MethodA and MethodB both called gv.DataBind (). This made sense, since I assume that every call to GridView.DataBind () will result in an ODS request for the data and therefore trigger a data access method.

The strange thing is that when commenting on a MethodA method call, it still fires twice. Checking the call stack shows that the method starts first as a result of MethodB, and then again without a path, except for [External Code]. This covert load does not occur when I allow MethodA and MethodB to execute.

Any idea what is going on here? Any idea, what other code could I have that is requesting ODS data? I'm starting to think that all of these "codeless" data controls are more obfuscated and BS than they are worth it.

+3
source share
6 answers

I ran into this problem when we hid / show the gridview column dynamically in code.

, , http://forums.asp.net/t/1161164.aspx

+3

gridview , , / , gridview .

show/hide gridview Page_LoadComplete.

Page_LoadComplete , - , (, , ..) gridview.

+1

" MethodA, ". , , Page_Load. , AutoEventWireup = "true", http://www.aspdeveloper.net/tiki-index.php?page=ASPFaqEventsDoubleFire

0

gridview -

gv.DataSourceID=dsObjDataSource;

gv.DataBind() .

0

- , / . / , , , , PageLoad. - / DataBind() twofer.

0

DataBinding, , asp:DataList asp:ObjectDataSource.

This turned out because I used UserControl in the select options:

<asp:ControlParameter Name="GroupID" Type="Int32" DefaultValue="-1"
    ControlID="UserControl1" PropertyName="SelectedGroupID" />

I am tired of UserControls. I see how they can improve performance for grade 5, but they represent a complete waste of time at a higher level.

0
source

Source: https://habr.com/ru/post/1741171/


All Articles