Keep Tab Selected after Postback

Asked

Viewed 122 times

2

I’m trying to keep the tab selected, after the postback, I’m trying to do it this way:

<script type="text/javascript">
        $(function () {
            $("#myTabs").tabs({
                activate: function () {
                    var selectedTab = $('#myTabs').tabs('option', 'active');
                    $("#<%= hdnfldVariable.ClientID %>").val(selectedTab);
                },
                active: document.getElementById('<%= hdnfldVariable.ClientID %>').value
            });
        });
    </script>


<asp:HiddenField ID="hdnfldVariable" runat="server" />

Besides changing the design of tabs, it still doesn’t work. I’ve done several ways and none works, I use bootstrap on the page. I also tried this function, which also did not work:

<script type="text/javascript">
        var prm = Sys.WebForms.PageRequestManager.getInstance();

        prm.add_endRequest(function () {

            // Mantém ativa as mesmas tabs do último postBack
            var tabAtivaIndex = $('#<%= hdnfldVariable.ClientID %>').val();
            $("#myTabs").tabs({ selected: tabAtivaIndex });

        });

        $(document).ready(function () {
            $('#<%= fragment1.ClientID %>').click(function () {
                $('#<%= hdnfldVariable.ClientID %>').val("0");
            });
            $('#<%= fragment2.ClientID %>').click(function () {
                $('#<%= hdnfldVariable.ClientID %>').val("1");
            });
            $('#<%= fragment3.ClientID %>').click(function () {
                $('#<%= hdnfldVariable.ClientID %>').val("2");
            });
            $('#<%= fragment4.ClientID %>').click(function () {
                $('#<%= hdnfldVariable.ClientID %>').val("3");
            });
            $('#<%= fragment5.ClientID %>').click(function () {
                $('#<%= hdnfldVariable.ClientID %>').val("4");
            });
            $('#<%= fragment6.ClientID %>').click(function () {
                $('#<%= hdnfldVariable.ClientID %>').val("5");
            });
            $('#<%= fragment7.ClientID %>').click(function () {
                $('#<%= hdnfldVariable.ClientID %>').val("6");
            });
            $('#<%= fragment8.ClientID %>').click(function () {
                $('#<%= hdnfldVariable.ClientID %>').val("7");
            });
        });
    </script>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.