Eugene Niemand
Eugene Niemand

Reputation: 729

Double postback causes SelectedIndexChanged to fire which fires AutoPostback

I have a Gridview in a UpdateTemplate. I have four template fields in the four different columns. Each TemplateField has an UpdatePanel with a control in it. All the columns are sortable and the Gridview is page-able. Three of the template fields has DropDowns in the UpdatePanel and one has a Textbox, all these controls have AutoPostBack = True. All the UpdatePanels have UpdateMode = Conditional and ChildrenAsTriggers = false.

When I click sort or change page index and the results have not returned and do it again(click sort or page index) while it is busy the SelectedIndexChanged and TextChanged events fires on some of the controls.

It seems that depending on when I do this some of the results has been refreshed and there events don't fire but some are still busy, and the second Postback halts the first one and thinks that the values have changed and fires there respective AutoPostBackt events. When all the events fired the grid then displays the intended result set that was expected from the first sort or page index change.

Upvotes: 0

Views: 1561

Answers (2)

Ralph Lavelle
Ralph Lavelle

Reputation: 5769

Without having the same level of complexity as you do, in terms of nested controls, etc., I had a simliar question recently: Why do unrelated (autopostback) methods get called when an Asp.Net ListBox autopostback method is invoked? which I think might be relevant to your question.

My problem was particularly related to ListBox autopostback methods, and the fact that methods which shouldn't be called were in fact being called, and had to do with the SelectedIndex of the ListBoxes actually changing, much to my surprise, and therefore firing on postback, which could be solved by setting those ListBoxes' SelectedIndex to 0, as explained in a couple of answers to my original question.

Without being exactly the same as your problem, I think my linked question may have the same cause.

Upvotes: 1

Bryan
Bryan

Reputation: 8778

Is there a question here?

One thing you can do is add a "busy" display while waiting for the first Ajax call and disable the controls that would cause another postback. Remember what the first A stand for in AJAX: asynchronous.

Upvotes: 1

Related Questions