添加到母版页时,JQuery修复的标头不起作用

时间:2014-06-24 06:52:34

标签: jquery asp.net gridview

没有母版页,一切正常。 当我添加到母版页时,它无法正常工作。

请帮忙。请尽早回复。

以下是实际链接: http://www.asual.com/jquery/thead/

我的母版页:

<%@ Master Language="VB" CodeFile="DefaultMaster.master.vb" Inherits="DefaultMaster" %>

<%@ Register Src="~/UserControls/Header.ascx" TagName="Header" TagPrefix="ucHeader" %>
<%@ Register Src="~/UserControls/TopMenu.ascx" TagName="TopMenu" TagPrefix="ucTopMenu" %>
<%@ Register Src="~/UserControls/SiteMap.ascx" TagName="SiteMap" TagPrefix="ucSiteMap" %>
<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>BMS</title>
    <link href="../App_Themes/DefaultTheme/Images/icons/tab_favorite.png" rel="Shortcut Icon" />
    <link href="~/App_Themes/DefaultTheme/CSS/static.css" rel="stylesheet" type="text/css" />
    <link href="~/App_Themes/DefaultTheme/CSS/content.css" rel="stylesheet" type="text/css" />
    <link href="~/App_Themes/DefaultTheme/CSS/AjaxClass.css" rel="stylesheet" type="text/css" />
    <link href="~/App_Themes/DefaultTheme/CSS/theme.css" rel="stylesheet" type="text/css" />
    <!--------------------JQuery CSS Section--------------->
    <link rel="stylesheet" href="~/App_Themes/DefaultTheme/ui/css/redmond/jquery-ui-1.8.17.custom.css" />
    <link href="../App_Themes/DefaultTheme/CSS/ui.jqgrid.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/treeview/jquery.treeview.css" rel="stylesheet" type="text/css" />
    <!--------------------JQuery JS--------------->
    <script type="text/javascript" src="../App_Themes/DefaultTheme/ui/js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../App_Themes/DefaultTheme/ui/js/jquery-ui-1.8.17.custom.min.js"></script>
    <script type="text/javascript" src="../Scripts/trirand/i18n/grid.locale-en.js"></script>
    <script type="text/javascript" src="../Scripts/trirand/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="../Scripts/treeview/lib/jquery.cookie.js"></script>
    <script type="text/javascript" src="../Scripts/treeview/jquery.treeview.js"></script>
    <script type="text/javascript" src="../Scripts/Custom_UI.js"></script>

    <!---------------------End------------------------>
    <!---------------------Starting new style link------------------------>
    <link href="../App_Themes/DefaultTheme/CSS/ddsmoothmenu.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../App_Themes/DefaultTheme/Javascript/ddsmoothmenu.js"></script>
    <!---------------------End------------------------>
    <script language="javascript" type="text/javascript">
        // Track key presses
        document.onkeydown = checkKeyCode;
        {
            // global variables used by checkKeyCode and checkForBrowserClose functions
            var oldKeyCode;
            var closingKey;
            // what key was pressed?
            function checkKeyCode(key) {
                var keyCode;
                if (window.event) {
                    keyCode = window.event.keyCode;
                }
                else if (key) {
                    keyCode = key.which;
                }
                // If the user pressed the Alt key(18) and then F4(115), they are trying to close the browser
                if ((keyCode == 115) && (oldKeyCode == 18)) {
                    // alert(keyCode);
                    closingKey = true;
                    window.location.href = 'Login/Logout.aspx';
                }
                oldKeyCode = keyCode;
            }
        }
    </script>
    <script language="javascript" type="text/javascript">
        // onkeydown="if (event.keyCode==8) {event.keyCode=0; return event.keyCode; }" 
        var isNS = (navigator.appName == "Netscape") ? 1 : 0;
        var EnableRightClick = 1; //Make 1 to view source
        if (isNS)
            document.captureEvents(Event.MOUSEDOWN || Event.MOUSEUP);
        function mischandler() {
            if (EnableRightClick == 1) { return true; }
            else { return false; }
        }
        function mousehandler(e) {
            if (EnableRightClick == 1) { return true; }
            var myevent = (isNS) ? e : event;
            var eventbutton = (isNS) ? myevent.which : myevent.button;
            if ((eventbutton == 2) || (eventbutton == 3)) return false;
        }
        function keyhandler(e) {
            var myevent = (isNS) ? e : window.event;
            if (myevent.keyCode == 96)
                EnableRightClick = 1;
            return;
        }
        document.oncontextmenu = mischandler;
        document.onkeypress = keyhandler;
        document.onmousedown = mousehandler;
        document.onmouseup = mousehandler;
        document.onkeydown = showDown;
        //--> 
        function showDown() {
            if (document.all) {
                if (event.keyCode == 116) {
                    event.keyCode = 0;
                    return false;
                }
            }
        }

        function closeIt() {
            navigate("../Login.aspx");
            //event.returnValue = " " ;
        }
    </script>
    <!--JavaScript newly added-->
    <script type="text/javascript">
        ddsmoothmenu.init({
            mainmenuid: "smoothmenu1", //menu DIV id
            orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
            classname: 'ddsmoothmenu', //class added to menu's outer DIV
            //customtheme: ["#1c5a80", "#18374a"],
            contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
        })

        ddsmoothmenu.init({
            mainmenuid: "smoothmenu2", //Menu DIV id
            orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
            classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
            //customtheme: ["#804000", "#482400"],
            contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
        })

        // <![CDATA[
        var myMenu;
        window.onload = function () {
            myMenu = new SDMenu("my_menu");
            myMenu.init();
            /*var firstSubmenu = myMenu.submenus[0];
            myMenu.expandMenu(firstSubmenu); 
            var firstSubmenu1 = myMenu.submenus[1];
            myMenu.expandMenu(firstSubmenu1); */
        };
        //          // ]]>
        //          $(document).ready(function () {

        //              $(".ddsmoothmenu ul").hide();
        //              $(".ddsmoothmenu li").hover(
        //      function () {
        //          $('ul:first', this).show();
        //      },
        //      function () {
        //          $('ul:first', this).hide();
        //      });

        //          });
    </script>
    <!--End-->
</head>
<body>
    <div class="page">
        <ucHeader:Header ID="Header1" runat="server" />
        <div id="loginInfo">
            <label>
                Welcome
                <%=UserInfo.GetUserInfo.FullName%>
                | [&nbsp;<a id="logOff" href="~/Login/Logout.aspx" runat="server">Log Out</a>&nbsp;]</label>
        </div>
        <div id="wrapper">
            <form id="form1" runat="server">
            <asp:ScriptManager ID="Scriptmanager1"  runat="server" EnableHistory="true" >
            </asp:ScriptManager>
            <div id="topMenuContainer">
                <%--<ucTopMenu:TopMenu ID="tpmenu" runat="server" />AsyncPostBackTimeout="36000" OnNavigate="OnNavigateHistory" 
                EnableHistory="true" EnableSecureHistoryState="false" --%>
                <div id="PortalTopMenu" runat="server">
                </div>
            </div>
            <div id="pageContent">
                <div id="progressBar">
                    <ucSiteMap:SiteMap ID="SiteMap1" runat="server" />
                </div>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <div style="width: 100%; height: 100%;">
                            <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                                <ProgressTemplate>
                                    <asp:Panel ID="UpdateProgressPanel" runat="server" Width="100%" Height="100%">
                                        <div style="position: absolute; width: 100%; height: 100%; background-color: Gray;
                                            z-index: 1000; opacity: 0.4;">
                                        </div>
                                        <div style="position: absolute; top: 48%; left: 48%; z-index: 1001">
                                            <asp:Image ID="Image1" ImageUrl="../App_Themes/DefaultTheme/Images/Spinner.gif" runat="server" />
                                        </div>
                                    </asp:Panel>
                                </ProgressTemplate>
                            </asp:UpdateProgress>
                            <asp:AlwaysVisibleControlExtender ID="AlwaysVisibleControlExtender1" TargetControlID="UpdateProgressPanel"
                                VerticalSide="Top" VerticalOffset="0" HorizontalSide="Left" HorizontalOffset="0"
                                runat="server" />
                        </div>


  <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
                        <asp:ContentPlaceHolder ID="ContentBody" runat="server">
                        </asp:ContentPlaceHolder>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
            </form>
        </div>
    </div>
</body>
</html>

和子页面:

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPages/DefaultMaster.master"
    AutoEventWireup="false" CodeFile="InvoiceDailyBalance.aspx.vb" Inherits="Pages_InvoiceDailyBalance" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentBody" runat="Server">
   <script type="text/javascript" src="../Scripts/jquery.thead-1.1.min.js"></script> 
    <div id="content">
        <div id="content_header" class="no_expand">
            <div id="header_title">
                <label class="header">
                    Invoice Daily Balance</label>
            </div>
            <div id="header_menu">
                <div id="validation">
                    <asp:Label ID="lblMessage" runat="server"></asp:Label>
                    <asp:ValidationSummary ID="vgSearch" runat="server" ValidationGroup="vgSearch" CssClass="errorMsg" />
                </div>
            </div>
            <div id="content_main">
                <div id="content_main_top">
                    <fieldset>
                        <!--Displays the filedset label-->
                        <legend>Inputs</legend>
                        <div class="field_content">
                            <table>
                                <tr>
                                    <td>
                                        <label class="title">
                                            Operator Name</label>
                                            </td> 
                                        <td>
                                            <label class="title">
                                                Start Date
                                            </label>
                                        </td>
                                        <td>
                                            <label class="title">
                                                End Date
                                            </label>
                                        </td>
                                        <td>
                                        </td>
                                </tr>
                                <tr>
                                    <td class="fields">
                                        <asp:DropDownList ID="ddlOptName" runat="server" AutoPostBack="False" CssClass="dd_box"
                                            Height="24px">
                                        </asp:DropDownList>
                                        &nbsp;
                                        <asp:RequiredFieldValidator ID="rfvddlOptName" runat="server" Display="Dynamic" ControlToValidate="ddlOptName"
                                            ErrorMessage="Please Select Operator Name." ValidationGroup="vgSearch" CssClass="errorMsg">*
                                        </asp:RequiredFieldValidator>
                                    </td>
                                    <td>
                                        <%--<asp:TextBox ID="txtStrtDateSearch" runat="server" Text="" Width="110px" 
                                            Height="18px"></asp:TextBox>
                                        <asp:TextBoxWatermarkExtender ID="tbwetxtStartDateEdit" runat="server" TargetControlID="txtStrtDateSearch"
                                            WatermarkText="dd/mm/yyyy" WatermarkCssClass="watermarked" />
                                        <asp:MaskedEditExtender ID="meedtxtStartDateEdit" runat="server" Mask="99/99/9999"
                                            TargetControlID="txtStrtDateSearch" ClearMaskOnLostFocus="true" MaskType="Date">
                                        </asp:MaskedEditExtender>
                                        <asp:CalendarExtender ID="txtStartDateEdit_CalendarExtender" runat="server" Enabled="True"
                                            TargetControlID="txtStrtDateSearch" Format="dd/MM/yyyy" PopupButtonID="txtStrtDateSearch">
                                        </asp:CalendarExtender>
                                        <asp:RequiredFieldValidator ID="rfvtxtStrtDateSearch" runat="server" Display="Dynamic"
                                            ControlToValidate="txtStrtDateSearch" ErrorMessage="Please enter Start Date."
                                            ValidationGroup="vgShow" CssClass="errorMsg">*
                                        </asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="revtxtStartDateEdit" runat="server" ControlToValidate="txtStrtDateSearch"
                                            ErrorMessage="Please enter valid Start date" ValidationExpression="^(?:((31/(01|03|05|07|08|10|12))|(((0[1-9]|[12][0-9])|30)/(01|03|04|05|06|07|08|09|10|11|12))|((0[1-9]|[12][0-9]|2[0-8])/02))|(29/02(?=-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))/((1[6-9]|[2-9]\d)\d{2})$"
                                            ValidationGroup="vgShow" CssClass="errorMsg">*</asp:RegularExpressionValidator>&nbsp;--%>
                                        <asp:TextBox ID="txtStrtDateSearch" runat="server" CssClass="txt_small"></asp:TextBox>
                                        <asp:TextBoxWatermarkExtender ID="tbwetxtStrtDateSearch" runat="server" TargetControlID="txtStrtDateSearch"
                                            WatermarkText="dd/mm/yyyy" WatermarkCssClass="watermarked" />
                                        <asp:MaskedEditExtender ID="meetxtStrtDateSearch" runat="server" Mask="99/99/9999"
                                            TargetControlID="txtStrtDateSearch" ClearMaskOnLostFocus="true" MaskType="Date">
                                        </asp:MaskedEditExtender>
                                        <asp:CalendarExtender ID="txtStrtDateSearch_CalendarExtender" runat="server" Enabled="True"
                                            TargetControlID="txtStrtDateSearch" Format="dd/MM/yyyy" PopupButtonID="txtStrtDateSearch">
                                        </asp:CalendarExtender>
                                        <asp:RequiredFieldValidator ID="rfvtxtStrtDateSearch" runat="server" Display="Dynamic"
                                            ControlToValidate="txtStrtDateSearch" ErrorMessage="Please Enter Start date"
                                            ValidationGroup="vgSearch" CssClass="errorMsg">*
                                        </asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="rexvtxtStrtDateSearch" runat="server" ControlToValidate="txtStrtDateSearch"
                                            ErrorMessage="Please enter valid Start date" ValidationExpression="^(?:((31/(01|03|05|07|08|10|12))|(((0[1-9]|[12][0-9])|30)/(01|03|04|05|06|07|08|09|10|11|12))|((0[1-9]|[12][0-9]|2[0-8])/02))|(29/02(?=-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))/((1[6-9]|[2-9]\d)\d{2})$"
                                            ValidationGroup="vgSearch" CssClass="errorMsg">*</asp:RegularExpressionValidator>
                                    </td>
                                    <td class="fields">
                                        <asp:TextBox ID="txtEndDateSearch" runat="server" Text="" CssClass="txt_small"></asp:TextBox>
                                        <asp:TextBoxWatermarkExtender ID="tbwetxtEndEdit" runat="server" TargetControlID="txtEndDateSearch"
                                            WatermarkText="dd/mm/yyyy" WatermarkCssClass="watermarked" />
                                        <asp:MaskedEditExtender ID="meedtxtEndDateEdit" runat="server" Mask="99/99/9999"
                                            TargetControlID="txtEndDateSearch" ClearMaskOnLostFocus="true" MaskType="Date">
                                        </asp:MaskedEditExtender>
                                        <asp:CalendarExtender ID="txtEndDateEdit_CalendarExtender" runat="server" Enabled="True"
                                            TargetControlID="txtEndDateSearch" Format="dd/MM/yyyy" PopupButtonID="txtEndDateSearch">
                                        </asp:CalendarExtender>
                                        <asp:RequiredFieldValidator ID="rfvtxtEndDateSearch" runat="server" Display="Dynamic"
                                            ControlToValidate="txtEndDateSearch" ErrorMessage="Please Enter End date" ValidationGroup="vgSearch"
                                            CssClass="errorMsg">*
                                        </asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="revtxtEndDateEdit" runat="server" ControlToValidate="txtEndDateSearch"
                                            ErrorMessage="Please enter valid End date" ValidationExpression="^(?:((31/(01|03|05|07|08|10|12))|(((0[1-9]|[12][0-9])|30)/(01|03|04|05|06|07|08|09|10|11|12))|((0[1-9]|[12][0-9]|2[0-8])/02))|(29/02(?=-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))/((1[6-9]|[2-9]\d)\d{2})$"
                                            ValidationGroup="vgSearch" CssClass="errorMsg">*</asp:RegularExpressionValidator>
                                        <asp:CompareValidator ID="cmpVal1" ControlToCompare="txtStrtDateSearch" ControlToValidate="txtEndDateSearch"
                                            Type="Date" Operator="GreaterThanEqual" ErrorMessage="End date should not be less then Start Date"
                                            runat="server" ValidationGroup="vgSearch" CssClass="errorMsg">*</asp:CompareValidator>
                                    </td>
                                    <td>
                                        <asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="submitBtn" ValidationGroup="vgSearch"
                                            CausesValidation="true" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </fieldset>
                </div>
                <div id="content_main_bottom" class="sample jquery-thead" >
                    <asp:GridView ID="gvInvoicedDailyBalance" runat="server" AutoGenerateColumns="false"
                        ShowFooter="True" CssClass="gridView" AlternatingRowStyle-CssClass="gv_altRow"
                        FooterStyle-CssClass="gv_footer" PagerStyle-CssClass="gv_pager" EmptyDataText="No Data Found">
                        <AlternatingRowStyle CssClass="gv_altRow"></AlternatingRowStyle>
                        <Columns>
                            <asp:BoundField DataField="Billing Date" HeaderText="Billing Date" />
                            <asp:BoundField DataField="Start Balance" HeaderText="Start Balance" />
                            <asp:BoundField DataField="Payment or Receipt" HeaderText="Payment or Receipt" />
                            <asp:BoundField DataField="Adjustment" HeaderText="Adjustment" />
                            <asp:BoundField DataField="No Of Call" HeaderText="No Of Call" />
                            <asp:BoundField DataField="Chargeable Duration" HeaderText="Chargeable Duration" />
                            <asp:BoundField DataField="Chargeable Amount" HeaderText="Chargeable Amount" />
                            <asp:BoundField DataField="End Balance" HeaderText="End Balance" />
                            <asp:BoundField DataField="% Of Utilization" HeaderText="% Of Utilization" />
                            <asp:BoundField DataField="Status" HeaderText="Status" />
                        </Columns>
                    </asp:GridView>
                </div>
            </div>
        </div>
    </div>
</asp:Content>

我刚刚在aspx.vb页面中添加了:

 Protected Sub gvInvoicedDailyBalance_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvInvoicedDailyBalance.PreRender
        If gvInvoicedDailyBalance.Rows.Count > 0 Then
            gvInvoicedDailyBalance.DataBind()
            gvInvoicedDailyBalance.HeaderRow.TableSection = TableRowSection.TableHeader
        End If
    End Sub

2 个答案:

答案 0 :(得分:0)

请在母版页中添加内容地点持有者。

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

然后将您的jquery文件放在<head>标记下。它可能会起作用

答案 1 :(得分:0)

主要问题是JQuery文件。令人惊讶的是,链接:http://www.asual.com/jquery/thead/ JQuery文件是jquery-1.4.2.min.js。如果我添加此文件作为参考,它的工作正常,虽然我有最新的文件jquery-1.7.1.min.js。但它不起作用。

然后我删除最新的JQuery min文件并添加了jquery-1.4.2.min.js。现在这个工作正常。但在那之后,出现了一个问题。页面回发后它无法正常工作。

然后我补充说:

<script type="text/javascript">
      var prm = Sys.WebForms.PageRequestManager.getInstance();
      prm.add_endRequest(function () {
          $('#div_id').thead();
      });

      $(document).ready(function () {
          $("#div_id").thead();
      })
  </script>

在此之后,一切正常。但仍有一个问题。 JQuery最新的min文件不起作用。我很惊讶。你找到任何理由吗?请告诉我。