I have a DataList that has a collection of People attached to it, and each Person has a button that, when clicked, should trigger an asynchronous postback, so the OnClick event handler can change the details specified in the UpdatePanel [the list of data is outside of UpdatePanel].
I made two attempts to set the Button to change the UpdatePanel in the DataList OnItemDataBound event handler. One assigns AsyncPostBackTrigger to UpdatePanel, and the other to RegisterAsyncPostBackControl for ScriptManager. Both work, but only for the first time. If another βPersonβ button [or the same button] is pressed, the page is completely sent back.
UpdatePanel UpdateMode is Conditional, and ScriptManager is EnablePartialRenderingEnablePartialRendering set to true.
Code in OnItemDataBound:
Button btnShowNotes = e.Item.FindControl( "btnShowNotes" ) as Button;
// Trigger
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = btnShowNotes.UniqueID;
trigger.EventName = "Click";
upDetails.Triggers.Add( trigger ); // UpdatePanel
// The trigger or this is used, not both
ScriptManager1.RegisterAsyncPostBackControl( btnShowNotes );
As soon as the first Async PostBack happened, it seems to have lost the link, but certainly it can be saved without constantly rewriting the DataList? I must have missed something while trying to do this.
Rich source
share