2015-10-10 25 views
1

在我的網站我有一個gridview裏面的中繼器。中繼器項目位於可以展開或摺疊的隱藏面板中。要記住頁面重新加載時打開哪些面板我使用jQuery Cookie。一切正常。 對於GridView中的控件,我想使用例如asp CompareValidator。如果我這樣做,在Firefox中我看到的錯誤 類型錯誤:$ .cookie不是一個函數驗證在GridView中創建jQuery Cookie中

在我使用項目: jquery.cookie.js 1.4.1和jQuery的2.1.4.js。

這是我的js代碼:

var expandCookieKey = "cookie_Expand"; 

    function saveButtonMouseOver() { 
     this.focus(); 
    } 

    $(function() { 
     $gridArray = $('.expandableGrid'); 
     checkCookie(expandCookieKey); 

    }); 


    function createExpandCookie(aiCookieKey, aiCookieValue) { 
     if ($.cookie(aiCookieKey) != null) 
      $.removeCookie(aiCookieKey); 

     $.cookie(aiCookieKey, aiCookieValue); 
    } 

    function checkCookie(aiCookieKey) { 
     if ($.cookie(aiCookieKey) != null) { 
      var index = $.cookie(aiCookieKey); 
      $($gridArray[index]).slideDown('slow'); 
     } 
    } 

    function expandContainer(aiClickedElement) { 

     var $thisExpand = $(aiClickedElement).parent('.expandContainer').children('div.expandableGrid'); 
     $gridArray 
      .filter(':visible') 
      .not($thisExpand) 
      .slideUp('slow'); 
     $thisExpand.is(":visible") ? $thisExpand.slideUp('slow') : $thisExpand.slideDown('slow'); 
     createExpandCookie(expandCookieKey, $gridArray.index($thisExpand)); 
    } 

這是我的aspx的網站的一部分。

<asp:Content ContentPlaceHolderID="HeadContent" runat="server"> 
    <style type="text/css"> 
     .version-hidden { 
      display: none; 
      height: auto; 
      padding: 10px; 
     } 

     .editTapete { 
      padding-top: 10px; 
      padding-right: 10px; 
     } 

     .header { 
      width: 100%; 
      height: 50px; 
      padding: 10px; 
      margin-bottom: 15px; 
      font-size: 24px; 
      background: #f1f1f1; 
      color: #000; 
      font-weight: bold; 
      border: 1px solid #dbdbdb; 
     } 

     .header .description{ 
      margin-top: 7px; 
      float: right; 
      *right: 0px; 
      font-size: 12px; 
      font-weight: 300; 
     } 

     .expandContainer { 
      width: 100%; 
      display: block; 
      *min-height: 30px; 
      color: #fff; 
      padding: 5px 10px; 
      background: #337ab7; 
      overflow: auto; 
      border: 1px solid #dbdbdb; 
     } 

     .label { 
      font-size: 16px; 
      padding-left: 10px; 
     } 

     .expandableGrid { 
      display: none; 
      height: auto; 
      padding: 5px; 
      *margin: 15px; 
      color: #337ab7; 
      overflow: auto; 
     } 
    </style> 
</asp:Content> 
<asp:Content ContentPlaceHolderID="MainContent" runat="server"> 

    <div class="row"></div> 
    <div class="row"> 
     <div class="col-lg-1"></div> 
     <div class="col-lg-11"> 
      <div class="input-group custom-panel-item" style="margin-bottom: 30px; width: 100%;" > 
       <div class="input-group-addon"> 
        <span class="glyphicon glyphicon-list"></span> 
       </div> 
       <input type="text" class="form-control textbox-cursor" style="font-weight: 600; font-size: 14px;" id="invLabel" runat="server" disabled /> 
      </div> 

      <asp:Repeater ID="repeater_ProjectInvestSections" SelectMethod="GetSectionsToUA" runat="server" ItemType="AWS_PV.nsPocos.nsTapete.MainGroup" OnItemCommand="repeater_ProjectInvestSections_ItemCommand"> 
       <SeparatorTemplate> 
        <span style="height: 5px; background: #fff; width: 100%; display: block; position: relative;"></span> 
       </SeparatorTemplate> 
       <ItemTemplate> 
        <div class="expandContainer"> 
         <span class="glyphicon glyphicon-chevron-down" style="cursor: pointer; padding-top: 10px;" onclick="expandContainer(this);"></span> 
         <span class="label textbox-cursor" style="display: inline-block; position: relative; height: 40px; padding-top: 10px;"><%# Item.Description %></span> 
         <asp:Label ID="label_HiddenSectionId" Text="<%# Item.ID %>" runat="server" Visible="false" /> 
         <span class="btn" style="position:absolute; right:20px"> 
         <asp:LinkButton runat="server" ID="editSection" CssClass="btn btn-default" CommandName="Edit" > 
           <i aria-hidden="true" class="glyphicon glyphicon-pencil"></i> 
          </asp:LinkButton> 
         </span> 
         <span class="btn" style="position:absolute; right:80px"> 
         <asp:LinkButton runat="server" ID="saveSection" CssClass="btn btn-default" CommandName="Save" > 
           <i aria-hidden="true" class="glyphicon glyphicon-floppy-disk"></i> 
          </asp:LinkButton> 
         </span> 
        <div class="expandableGrid"> 
         <asp:GridView ID="Gridview_ProjectInvest" runat="server" DataSourceID="dataSource_InvestCostsToSection" AutoGenerateColumns="false" 
          GridLines="Vertical" CellPadding="2" BackColor="White" 
          HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" 
          ItemType="AWS_PV.nsPocos.ProjectInvestObj" 
          CssClass="table table-bordered table-condensed" 
          OnRowDataBound="Gridview_ProjectInvest_RowDataBound" ShowFooter="true" DataKeyNames="InvestID,fachgrpRef"> 
         <Columns> 
          <asp:TemplateField HeaderText="Benennung" > 
           <ItemTemplate> 
            <asp:Label ID="Beschreibung" runat="server" Text='<%# Item.Beschreibung %>' /> 
            <asp:TextBox ID="editBeschreibung" runat="server" Text='<%#Eval("Beschreibung") %>' MaxLength="255" Width="530" Visible="false" BackColor="Yellow"/> 
<         <asp:RequiredFieldValidator ID="valBeschreibung" runat="server" ControlToValidate="editBeschreibung" 
             Display="Dynamic" ErrorMessage="Eine Beschreibung ist notwendig." ForeColor="Red" SetFocusOnError="True" 
             ValidationGroup="editGrp">Eine Beschreibung ist notwendig. 
            </asp:RequiredFieldValidator> 
           </ItemTemplate> 
          </asp:TemplateField> 
         </Columns> 
         </asp:GridView> 
         <asp:ObjectDataSource ID="dataSource_InvestCostsToSection" runat="server" SelectMethod="Gridview_GetData" TypeName="Subpages.EditProject.Project" DataObjectTypeName="SP_AWS_GetInvest"> 
          <SelectParameters> 
           <asp:ControlParameter ControlID="label_HiddenSectionId" Name="aiSectionId" Type="Int32" /> 
          </SelectParameters> 
         </asp:ObjectDataSource> 
         </div> 
        </div> 
       </ItemTemplate> 
      </asp:Repeater> 
     </div> 
    </div>  

怎麼了? 任何幫助,將不勝感激。

+0

請出示你是如何調用方法'checkCookie()'你的文章是很明朗,同時,請在哪個階段你的對象不支持屬性或方法cookie這個錯誤。 – Prabhat

+0

我有更新我的問題,併發布我使用的所有JavaScript。頁面加載時出現錯誤。 –

回答

0

我的問題很不清楚。但是現在我找到了解決方案。

Answer in old question

你必須改變你的web.config這樣的:

<appSettings> 
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/> </appSettings> 
+0

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 –