Monday, March 26, 2012

ListSearchExtender error - System.InvalidOperationException: Extender controls may not be

I created a custom web control (ListSearchControl) using the ListBox and ListSearchExtender control. I added this control to another custom control which is dynamically added to a page. The page ahs a ScriptManager tag before any other controls and inside Form tag. The control works fine on page laod, but gives an error on post back - "System.InvalidOperationException: Extender controls may not be registered after PreRender".

I tried using the same custom control((ListSearchControl) adding it to the page directly and it works fine even on postback.

Is there any way to get out of the error in the first case, or is there a known problem with using Control toolkit extenders being added dynamically on the page?

Hi,

Please try the workaround in this thread : http://forums.asp.net/t/1160803.aspx

Nai-Dong Jin - MSFT:

Hi,

From your description, it seems that while you are usingASP.NET AJAX Toolkit with your controls, you'll get a message whichsays "Extender controls may not be registered after PreRender", right?

For this kind of issue, one workaround is to call the baseOnPreRender method before declaring your controls while overriding theOnPreRender method on the page where you had the new extender control.See the following code snippet:

protected override void OnPreRender(EventArgs e)
{
// add base.OnPreRender(e); at the beginning of the method.
base.OnPreRender(e);

// codes to handle with your controls.
...


}

Also, there's a good sample on how to create an ASP.NET AJAX Toolkit Extender Control to Extend an standard control. See,
http://weblogs.asp.net/dwahlin/archive/2007/08/08/creating-an-asp-net-ajax-toolkit-extender-control.aspx

No comments:

Post a Comment