Zhi-QiangNi's tech blog--AJAX's paradise
I'm working at the Microsoft IBS DevDiv Community Support Team, in charge of the customer service of ASP/AJAX forum. Welcome to my blog and AJAX forum, anyone interested in ASP.Net Ajax can discuss it with me. :-)

We all know the Extenders of the AjaxControlToolkit implement their Client Partial-Refresh action by using their Client behaviors which are generated after they are rendered. In addition, the client classes provide many useful APIs that enable you to bind to events and to provide handlers for those events.

For example, the AutoComplete Extender's client behavior document would like this:

The AutoCompleteExtender

Code

Its Client Behaviior Document

You may notice that we simply used this method "$find(the Extender's BehaviorID)" to get the Client Behavior Document. If the BehaviorId is not defined, we can use this "$find(<%=the Extender's ClientID%>)".

But sometimes things are not so simple. If we place the Extender inside a DataBind Control's ItemTemplete, such as GridView. The same method would raise error which sames like this:

Sys.InvalidOperationException:Two components with the same id 'XXXXXBehavior1' can't be added to the application.

That's because the BehaviorId shoule be unique.

Then, how can we get the Behaviors in this situation?

Actually, every behavior has been cached into the Sys.Application's Components object after the page client initialize phase in the Life-Cycle. When script in a load event handler runs, all scripts and components have been loaded and are available. That's the key to achieve our goal.

Code

 

 

posted on 2009-01-15 14:52  Zhi-Qiang Ni  阅读(1576)  评论(2编辑  收藏  举报