How to always start an asynchronous PostBack for UpdatePanel using a button in a DataList?

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.

+5
source share
2 answers

I came up with a solution, although I'm not sure if this is the best / most optimal. On each PostBack method in the Page_Load method, I look through the elements and register the Aync PostBack on the buttons:

if ( IsPostBack )
{
    foreach ( DataListItem item in gvAllUsers.Items )
    {
        btnShowNotes = item.FindControl( "btnShowNotes" ) as ImageButton;
        ScriptManager1.RegisterAsyncPostBackControl( btnShowNotes );
    }
}
+3
source

ToolkitScriptManager1.RegisterAsyncPostBackControl (ibtnShowPicker) you must put above code page_load ibtnShowPicker is the identifier

0

All Articles