2015-03-13 36 views
0

我有一個母版頁和內容頁面,當我從下拉列表中選擇一個值(例如)在任何標籤中使用autopostback時,它不保留在選定的標籤中,轉到第一個標籤:(我的腳本代碼(關於保持選擇在隱藏字段標籤索引和設置TAB回傳後該指數)是在母版頁如何在jquery中的autopostback後維護選定的選項卡?

我的母版頁:

<%@ 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"]; 
+0

'autopostback'似乎是一些ASP的東西。爲了吸引合適的專家,我建議你添加一個ASP標籤。我會自己做,但有幾個「ASP ...」標籤可供選擇。 – 2015-03-13 14:03:10

+0

感謝您的建議,我現在添加了 – kykbr 2015-03-13 14:24:06

回答

0

此代碼有效!當我選擇一個選項卡中選擇標籤選項卡中的值不改變

<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> 
0

將此腳本添加到您的頁面。

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

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

     )}; 

</script> 
相關問題