gridview中的验证器在jquery cookie中创建

时间:2015-10-10 16:03:28

标签: c# jquery validation gridview cookies

在我的网站中,我有一个带有gridview的转发器。转发器项目位于可以展开或折叠的隐藏面板中。要记住在页面重新加载时打开了哪些面板,我使用jquery cookie。一切正常。 对于gridview中的控件,我想使用例如asp CompareValidator。如果我在Firefox中这样做,我会看到错误 TypeError:$ .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>     

有什么不对? 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我的问题很不清楚。但现在我找到了解决方案。

Answer in old question

您必须像这样更改您的web.config:

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