How to handle the Accordion's SelectedIndexChanged event at client side?

Some programmers would like to find a function to handle the Accordion’s SelectedIndexChanged event. As we all know, the Accordion’s Client behavior has provided such two events:

ContractedBlock.gif ExpandedBlockStart.gif Code
add_selectedIndexChanged(handler)
add_selectedIndexChanging(handler)

 

Now, let's have a look at how to add a confirmation when the Accordion pane header is clicked.

 

ContractedBlock.gif ExpandedBlockStart.gif Code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestHandleSelectedChangedEvent.aspx.vb"
    Inherits
="SoluTest_Accordion.TestHandleSelectedChangedEvent" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title></title>
    
<style type="text/css">
        .accordionHeader
        
{
            border
: 1px solid #2F4F4F;
            color
: white;
            background-color
: #2E4d7B;
            font-family
: Arial, Sans-Serif;
            font-size
: 12px;
            font-weight
: bold;
            padding
: 5px;
            margin-top
: 5px;
            cursor
: pointer;
            height
: 10px;
        
}
        .accordionHeaderSelect
        
{
            border
: 1px solid #2F4F4F;
            color
: red;
            background-color
: #2E4d7B;
            font-family
: Arial, Sans-Serif;
            font-size
: 12px;
            font-weight
: bold;
            padding
: 5px;
            margin-top
: 5px;
            cursor
: pointer;
            height
: 10px;
        
}
        .accordionContent
        
{
            background-color
: #D3DEEF;
            border
: 1px dashed #2F4F4F;
            border-top
: none;
            padding
: 5px;
            padding-top
: 10px;
        
}
    
</style>

    
<script type="text/javascript">
        
var accordion;
        
var handlerFired;
        
function pageLoad() {

            accordion 
= $find("Accordion1_AccordionExtender"); //parameter should be the ID_AccordionExtender
            accordion.add_selectedIndexChanged(selectedIndexChangedHandler)
        }
        
function selectedIndexChangedHandler(sender, args) {
            
if (handlerFired) {
                
//add this variable to prevent firing the handler twice.
                handlerFired = false;
                
return;
            }

            
if (confirm("Would you like to change the index from " + args._oldIndex + " to " + args._selectedIndex + "?")) {
                
return;
            } 
else {
                handlerFired 
= true;
                
// if we don't want to change the index, we need to set it to the old value.
                accordion.set_SelectedIndex(args._oldIndex);
            }
        }
    
    
</script>

</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:ScriptManager ID="ScriptManager1" runat="server" />
        
<cc1:Accordion ID="Accordion1" runat="server" HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelect"
            ContentCssClass
="accordionContent" FadeTransitions="True" FramesPerSecond="40"
            TransitionDuration
="250" AutoSize="None" RequireOpenedPane="false" SuppressHeaderPostbacks="false"
            SelectedIndex
="-1">
            
<Panes>
                
<cc1:AccordionPane ID="AccordionPane1" runat="server">
                    
<Header>
                        
<p>
                            Header1
</p>
                    
</Header>
                    
<Content>
                        
<p>
                            This is the content area!
</p>
                    
</Content>
                
</cc1:AccordionPane>
                
<cc1:AccordionPane ID="AccordionPane2" runat="server">
                    
<Header>
                        
<p>
                            Header2
</p>
                    
</Header>
                    
<Content>
                        
<p>
                            This is the content area!
</p>
                    
</Content>
                
</cc1:AccordionPane>
                
<cc1:AccordionPane ID="AccordionPane3" runat="server">
                    
<Header>
                        
<p>
                            Header3
</p>
                    
</Header>
                    
<Content>
                        
<p>
                            This is the content area!
</p>
                    
</Content>
                
</cc1:AccordionPane>
            
</Panes>
        
</cc1:Accordion>
    
</div>
    
</form>
</body>
</html>

 

The related thread url: http://forums.asp.net/t/1380353.aspx

转载于:https://www.cnblogs.com/Zhi-QiangNi/archive/2009/02/09/1386977.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值