如何在jquery中自动后备后维护选定的选项卡?

时间:2015-03-13 13:44:50

标签: c# jquery asp.net postback

我有一个母版页和内容页面,当我从任何选项卡中的autopostback中选择下拉列表中的值(例如)时,它不会保留在选定的选项卡中,转到第一个选项卡:(我的脚本代码(关于保持) HIDDENFİELD中选择的TAB索引以及在POSTBACK后设置TAB的这个索引)在母版页中

我的母版页:

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Main.master.cs" Inherits="YPNETYENI.Main" %>

<!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 id="Head1" runat="server">

    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />

    <title>YpNet | Personel Bilgi Sistemi</title>
    <link href="css/reset.css" rel="stylesheet" type="text/css" />
    <link href="css/chosen.css" rel="stylesheet" type="text/css" />
    <link href="css/style.css" rel="Stylesheet" type="text/css" />
    <!--[if lte IE 6]><link rel="stylesheet" href="css\style_ie.css" type="text/css" media="screen, projection" /><![endif]-->
    <link href="css/General.css" rel="stylesheet" type="text/css" />
    <link href="css/App.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />


    <script language="javascript" type="text/javascript">
        function ShowModal(Url, Width, Height) {
            var frame = $get('<%# ImFrame.ClientID %>');
            frame.width = Width;
            frame.height = Height;
            if ($find('mdlMain') = !null) {
                $find('mdlMain').show();
            }
            frame.src = Url;
        }
        function CloseModal() {
            $find('mdlMain').hide();
            var frame = $get('<%# ImFrame.ClientID %>');
            frame.src = '<%# ResolveClientUrl("~/ContentLoading.aspx") %>';
            return false;
        }
        function CancelScript() {
            var frame = $get('<%# ImFrame.ClientID %>');
            frame.src = '<%# ResolveClientUrl("~/ContentLoading.aspx") %>';
        }
        function OkayScript() {
            RefreshDataGrid();
            CancelScript();
        }
        function RefreshDataGrid() {
            // $get('btnRC').click();
            location.reload(true);
            //alert("location.reload activated");
        }


    </script>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">      </script>

    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>

    <script type="text/javascript">

        $(document).ready(function () {
            var tabs = $("#tabs").tabs({
                select: function (e, i) {
                    selected_tab = i.index;

                }

            });
            selected_tab = $("[id$=selected_tab]").val() != "" ? parseInt($("[id$=selected_tab]").val()) : 0;
            tabs.tabs('select', selected_tab);
            $("form").submit(function () {
                $("[id$=selected_tab]").val(selected_tab);

            });

        });
    </script>
       </head>
        <body>
      <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">            </asp:ScriptManager>
          <div id="wrapper">


            <div id="menu">
                <asp:ContentPlaceHolder ID="cphHorizontalMenu" runat="server">
                </asp:ContentPlaceHolder>
            </div>
            <!-- #menu-->

            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>

        </div>
        </form>
           </body>
            </html>

我的内容页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PersonelGiris.aspx.cs" MasterPageFile="~/MasterHMenu.master" Inherits="YPNETYENI.PersonelGiris" %>

<asp:Content ID="Content1" ContentPlaceHolderID="chpMain" runat="Server">



    <p id="clickme">cllick me</p>
    <div class="GDiv">


        <asp:Panel ID="pnlPersonelDuzenleme" runat="server">
            <div class="GDiv">



            <div class="tabs">

                <asp:PlaceHolder ID="phMain" runat="server" Visible="false">
                    <ul>

                        <li><a href="#tabs-1">Personel Information</a></li>
                        <li><a href="#tabs-3">Job information</a></li>
                        <li><a href="#tabs-5">language information </a></li>


                    </ul>


                    <div id="tabs-1" class="GDiv">

                        <table cellpadding="0" cellspacing="0" class="hastable">
                            <tbody>


                                <tr>
                                    <td align="left" style="width: 170px">
                                        <asp:Label ID="Label9" runat="server" CssClass="caption" Text="* Surname :"></asp:Label>
                                    </td>
                                    <td align="left" colspan="3">
                                        <asp:TextBox ID="txtSrname" runat="server" CssClass="txt" Width="224px" MaxLength="32"></asp:TextBox>
                                    </td>
                                </tr>


                            </tbody>
                        </table>

                    </div>

                    <div id="tabs-3" class="GDiv">

                        <table>
                            <tbody>


                                <tr>
                                    <td align="left" style="width: 170px">
                                        <asp:Label ID="Label51" runat="server" CssClass="caption" Text="* Birim :"></asp:Label>
                                    </td>
                                    <td align="left" colspan="2">
                                        <asp:DropDownList ID="cmbBirim" runat="server" AutoPostBack="true" CssClass="txt"
                                            Width="230px" OnSelectedIndexChanged="cmbBirim_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <asp:Label ID="lblBirim" runat="server"></asp:Label>
                                    </td>
                                </tr>
                                </tbody>
                        </table>
                    </div>

                    <div id="tabs-5" class="GDiv">
                        <div class="DTitle4">
                            <div class="fleft title">
                                <asp:Label ID="Label56" runat="server" Text="Language information"></asp:Label>
                            </div>
                            <span class="cleanb"></span>
                        </div>
                        <table cellpadding="0" cellspacing="0" class="hastable">
                            <tbody>

                                <asp:Repeater ID="rptDil" runat="server" OnItemDataBound="rptDil_ItemDataBound">
                                    <ItemTemplate>
                                        <tr>
                                            <td style="height: 37px; width: 170px;" align="left">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <asp:ImageButton ID="btnDilSil" runat="server" ImageUrl="~/Img/Icons/icon-delete.png"
                                                                CommandArgument="0" OnClick="btnDilSil_Click" />
                                                        </td>
                                                        <td>
                                                            <asp:DropDownList ID="cmbDil" runat="server" CssClass="txt" Width="150px">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td style="width: 205px; height: 30px;">
                                                <asp:DropDownList ID="cmbReading" runat="server" CssClass="txt" Width="75px">
                                                    <asp:ListItem Text="not bad" Value="1"></asp:ListItem>
                                                    <asp:ListItem Text="good" Value="2"></asp:ListItem>
                                                    <asp:ListItem Text="very good" Value="3"></asp:ListItem>
                                                </asp:DropDownList>
                                            </td>


                                        </tr>
                                    </ItemTemplate>
                                </asp:Repeater>
                                <tr>
                                    <td colspan="4">
                                        <asp:LinkButton ID="btnNewLanguage" runat="server" Font-Bold="True" OnClick="btnNewLanguage_Click">Add new language</asp:LinkButton>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>

                </asp:PlaceHolder>
            </div>
           <asp:HiddenField ID="selected_tab" runat="server" Value="0" />
        </asp:Panel>
    </div>

</asp:Content>

我将此代码行添加到.cs页面

        selected_tab.Value = Request.Form["selected_tab"];

2 个答案:

答案 0 :(得分:1)

此代码有效!当我在选项卡中选择asp控件中的值时,选项卡不会更改

<script type="text/javascript">
        $(document).ready(function () {
            var tabs = $(".tabs").tabs({
                activate: function (event, ui) {
                    localStorage.setItem("accIndex", $(this).tabs("option", "active"))
                },
                active: parseInt(localStorage.getItem("accIndex"))
            });
        });

</script>

答案 1 :(得分:0)

将此脚本添加到您的页面。

    <script>
       $(function(){         
           $('.tabs a').click(function(){           
                  $('#<%= selected_tab.ClientID %>').val($(this).index());
            });

            /// maintain tab
            $('.tabs ul').tabs('select',  $('#<%= selected_tab.ClientID %>').val());

       )};

</script>