Paul Juenger a.k.a. PJDev

Triggering an Update Panel from a control in a different ContentPlaceHolder

I can across an anamoly today when I tried to trigger an Update Panel from a control in a different ContentPlaceHolder.  The IDE recognized the control in the designer as I was able to select the control ID from the dropdown.  But, when I ran the page I received an error stating: "A control with ID 'Button1' could not be found for the trigger in UpdatePanel 'UpdatePanel1'." 

This is something I think should be fixed in the AJAX framework.  The Unique ID of the button is "ctl00$ContentPlaceHolder2$Button1", but the UpdatePanel is in ContentPlaceHolder1 so it assigned the controlID of the trigger to "ctl00$ContentPlaceHolder1$Button1" causing the YSOD ("Yellow Screen of Death").

The work around that I currently use is to dynamically add the trigger to the update panel.

AsyncPostBackTrigger trig = new AsyncPostBackTrigger();
trig.ControlID = Button1.UniqueID; //Unique ID, not client ID
trig.EventName = "Click";
UpdatePanel1.Triggers.Add(trig);

Comments

Ashish said:

This doesnot work for me the UniqueID on the server & the one actually created by ASP.NET are dfferent

# January 6, 2009 4:20 AM

pjdev said:

Ashish - I have this running on a couple of live sites and it is working correctly.  Email me a sample and I'll take a look at what you have.

# January 9, 2009 10:21 AM

Nathan said:

It's worth noting that if you must put this code in the Page_Init() method.

I mistakenly put it in my Page_Load() where it doesn't work, but I didn't actually realize at first because the UpdatePanel being triggered had UpdateMode set to Always, and was being refreshed from another UpdatePanel posting back, instead of the actual trigger firing.

Needless to say I was chasing my tail for a little while there, but now have the UpdatePanel being triggered set to a Conditional UpdateMode, and the triggers assigned programmatically (as above) within the Page_Init() method.

# April 27, 2009 5:58 PM

peter said:

Brilliant, works well for me.

# August 3, 2009 10:21 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)