2015-10-10 22 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

虽然这个链接可能回答这个问题,但最好在这里包含答案的重要部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 –