Geeks With Blogs
Marc Schuricht Killer Cubes

So, I came across a requirement where the users do not want to wade through a potential 100's of items in a combobox, but are stuck on using a combo box.  Our team has already built a generic server control which inherits from TableRow allowing us to add various controls as TableRows within an ASP:Table.

Essentially we get something like this:

<ASP:Table ID="Table1" runat="server">
Title="Pick an Item"
Description="Please Choose an Item from the list"
runat="server" />
. and so on

The interesting twist comes in when we want to implement the AJAX extender, found HERE, to search our list using AJAX. 

A couple decisions are made to start:
(1) there may be more than 1 ajax enabled control per page so the page needs to implement the script manager and not the server control.
(2) the server control should be self-contained and nothing external should know or care that the control is ajax-enabled. 

That said, here is the implementation:

[ToolboxData("<{0}:AjaxDropDownListFieldEditor runat=server></{0}:AjaxDropDownListFieldEditor>")]

    public class AjaxDropDownListFieldEditor : DropDownListFieldEditor


        private readonly ListSearchExtender searchExtender;


        public AjaxDropDownListFieldEditor()


            searchExtender = new ListSearchExtender();



        /// <summary>

        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.

        /// </summary>

        protected override void CreateChildControls()




            searchExtender.PromptText = "Enter Text";

            searchExtender.PromptPosition = ListSearchPromptPosition.Top;

            searchExtender.TargetControlID = Editor.UniqueID;






The magic happens in two places:


searchExtender.TargetControlID = Editor.UniqueID;


this ensures that we have the control’s unique server-side id, otherwise it complains that it cannot find the control.  Secondly here:




We need to ensure we add the searchExtender control to the Form’s control collection, not just the page control collection or the generic this.Controls.  If you add it to the page controls then the extender control  will not be placed in the within a form control with runat=”server”.  The latter will result in the extender not allowed to be added a TableRow control.



Posted on Wednesday, December 12, 2007 10:01 PM .NET 2.0 , Emerging Technologies , MOSS 2007 Application Development | Back to top

Comments on this post: AJAX Entender within Server Control

# re: AJAX Entender within Server Control
Requesting Gravatar...
how to use ajax controls
Left by shobha on Nov 13, 2009 5:48 AM

Your comment:
 (will show your gravatar)

Copyright © Marc Schuricht | Powered by: