问题缘起:
$find('ctl00_ContentPlaceHolder1_MyAccordion_AccordionExtender')
这里找的是什么呢?一开始我以为是找控件,实际上找的是一个AjaxToolKit控件的Behavior!
Asp.net Ajax 编程备忘录----细数28个服务器端控件 [原创]一文中的确是忽略了这一点


 
Accordion 行为标识 "_AccordionExtender";

Default constructor that tells ASP.NET to render it as a DIV

l             TransitionDuration  切换动画的长度               默认:500ms

l             FramesPerSecond   切换动画每秒多少帧           默认:15

l             FadeTransitions     切换过程中是否使用淡入淡出   默认:false

l             AutoSize           控件增长方式                默认:Autosize.None

l             SelectedIndex       展开的选项卡的Index               默认:0


页面脚本:
       
<script language="javascript" type="text/javascript">
            
function toggleFade() {
                
var behavior = $find('ctl00_ContentPlaceHolder1_MyAccordion_AccordionExtender');
                
if (behavior) {
                    behavior.set_FadeTransitions(
!behavior.get_FadeTransitions());
                }

            }

            
function changeAutoSize() {
                
var behavior = $find('ctl00_ContentPlaceHolder1_MyAccordion_AccordionExtender');
                
var ctrl = $get('autosize');
                
if (behavior) {
                    
var size = 'None';
                    
switch (ctrl.selectedIndex) {
                        
case 0 :
                            behavior.get_element().style.height 
= 'auto';
                            size 
= AjaxControlToolkit.AutoSize.None;
                            
break;
                        
case 1 :
                            behavior.get_element().style.height 
= '400px';
                            size 
= AjaxControlToolkit.AutoSize.Fill;
                            
break;
                        
case 2 :
                            behavior.get_element().style.height 
= '400px';
                            size 
= AjaxControlToolkit.AutoSize.Limit;
                            
break;
                    }

                    behavior.set_AutoSize(size);
                }

                
if (document.focus) {
                    document.focus();
                }

            }

        
</script>