I am stuck with some legacy code and I am trying to figure out why a certain page is called/loaded several times. It contains a gridview element. It turns out after some internet searching that there are several reasons why the page is loaded several times.
When the page is loaded the gridviews OnSelecting method is called twice. Once to populate the gridview, and once to count the elements in the gridview (ExecutingSelectCount).
Another reason the page is loaded several times in a row is if you add dynamic stylesheets in the code behind after you’ve bound the data to the gridview. This causes the page to load several times. Two times extra the be exact. This is seen when the OnSelecting method is called four times when the page loades.
Third reason is if you dynamically show/hide columns in the gridview. This causes some extra reloads, exactly as in the case of dynamic css above.
So, two calls to OnSelecting method is normal and according to spec. More calls might be because you are fiddling with the gridview after the databind call, causing it to reload. Try and move the logic to dynamically change the gridview earlier in the load of the page.