保持ASP.NET回发后开放目前jQuery的手风琴窗格? [英] Keep the current jQuery accordion pane open after ASP.NET postback?

查看:261
本文介绍了保持ASP.NET回发后开放目前jQuery的手风琴窗格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net ASPX weppage一个jquery手风琴。窗格内,我有asp.net按钮。当我按一下按钮,我就在窗格中,关闭并重新加载页面,默认为第一个窗格。我不介意重装,但有一种方法来保持当前窗格重装后打开。现在,我只是呼吁一个div手风琴()与手风琴的ID。

I have a jquery accordion on an asp.net aspx weppage. Inside the panes, I have asp.net buttons. When I click on the button, the pane I was in, closes and reloads the page, defaulting to the first pane. I don't mind the reload, but is there a way to keep the current pane open after the reload. Right now, I am just calling accordion() on a div with the id of accordion.

推荐答案

您可以使用一个隐藏的输入字段回发期间保持活跃手风琴索引,然后手风琴的改变事件中使用JavaScript来填充它。

You could use a hidden input field to persist the active accordion index during postbacks, and then populate it using javascript during the change event of the accordion.

<asp:HiddenField ID="hidAccordionIndex" runat="server" Value="0" />

<script language="javascript" type="text/javascript">
    $(function(){
        var activeIndex = parseInt($('#<%=hidAccordionIndex.ClientID %>').val());

        $("#accordion").accordion({
            autoHeight:false,
            event:"mousedown",
            active:activeIndex,
            change:function(event, ui)
            {
                var index = $(this).children('h3').index(ui.newHeader);
                $('#<%=hidAccordionIndex.ClientID %>').val(index);
            }
        });
    });
</script>

您也许可以想出改变事件中捕捉活动指数更有效的方式,但是这似乎工作。

You could probably come up with a more efficient way of capturing the active index during the change event, but this seems to work.

在页面加载它检索变量中的隐藏字段,并将其存储活动指数。然后,它初始化使用检索索引和自定义函数火上写了一个新的索引到隐藏字段,每当一个新的面板被激活更改事件的手风琴。

When the page has loaded it retrieves the active index from the hidden field and stores it in a variable. It then initialises the accordion using the retrieved index and a custom function to fire on the change event which writes a new index to the hidden field whenever a new pane is activated.

在回传,隐藏字段值在ViewState持续使得当页面被再次加载手风琴被初始化与最后窗格的索引点击

During a postback, the hidden field value is persisted in the ViewState so that when the page is loaded again the accordion is initialised with the index of the last pane clicked on.

这篇关于保持ASP.NET回发后开放目前jQuery的手风琴窗格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆