I have a Button which will trigger an UpdatePanel, but it is in a different container so if I put my code like below :
There will be a runtime server error : "A control with ID 'btnSearchFilter' could not be found for the trigger in UpdatePanel 'uptxtQuickSearch'."
So I've to register it on the Page_load event with ScriptManager :
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterAsyncPostBackControl(btnSearchFilter);
but in this case, I still have to update the UpdatePanel manually by using Update() method on the end of btnSearchFilter_click event.
Is there any way to update the panel automatically while registering the trigger on the code-behind?
Talk1:
If possible, I would encourage you to move away from updatepanels and the old way of doing ajax in asp.net. I find that it's much more manageable to do your ajax in javascript.
Talk2:
thanks for the feedback, did you mean like using jQuery.ajax method? I know it's resources-wise but I can't see the "much more manageable" part of it, can you help me find a site that explain it in details?
Talk3:
There are several tutorials online. Here is one example: code.tutsplus.com/tutorials/…
Talk4:
The downside to updatepanels/asp.net ajax toolkit is that it abstracts ajax to the point where many developers don't fully grasp the concept of it. I also find it to be inflexible.
Solutions1
I've found a solution for this issue. It turns out that you don't really need to register the control using RegisterAsyncPostBackControl method.
you just need to add the trigger on Page_Init event and use the control.UniqueID if the control cannot be found on the runtime.
So the aspx will be like this :
and in code-behind :
protected void Page_Init(object sender, EventArgs e)
{
uptxtQuickSearch.Triggers.Add(new AsyncPostBackTrigger() { ControlID = btnSearchFilter.UniqueID });
}