简体   繁体   English

Javascript 未加载到子页面中(从母版页继承)

[英]Javascript not loading in child page (Inherit from master page)

I'm currently trying to use a JS function in my child page, which is loaded in the master page, but it doesn't work.我目前正在尝试在我的子页面中使用 JS 函数,该函数已加载到母版页中,但它不起作用。

I've tried adding the scripts again, before calling them, which works, but it's unnecessary as it should already be loaded.我已经尝试在调用它们之前再次添加脚本,这可行,但没有必要,因为它应该已经加载了。

ManageKey.aspx管理密钥.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" 
    CodeBehind="ManageKey.aspx.cs"
    Inherits="PlisSmartSuiteLicenseToolsWebsite.Pages.ManageKey" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Panel runat="server" ID="contentPanel" Visible="false">
        <asp:Panel runat="server" ID="panelKeySelected" Visible="false">
            <div style="text-align:center;">
                <asp:CheckBox ID="checkBoxAllDetails" runat="server" 
                    Text="Show All Details" style="text-align: center;"
                    OnCheckedChanged="CheckBoxAllDetails_CheckedChanged"
                    AutoPostBack="true"/>
            </div>
            <div class="row newCustomer-container">
                <div id="licenseKeyInformationDiv" class="col-sm-10" 
                    style="text-align: center; overflow-x: auto; white-space: 
                        nowrap; margin-left: 8.33%; margin-right:1rem;">                
                    <asp:GridView id="licenseKeyInformationGridView"
                        CssClass="tablesorter"
                        OnPreRender="licenseKeyInformationGridView_PreRender" 
                        OnRowDataBound="LicenseKeyInformationGridView_RowDataBound" 
                        CellPadding="3" 
                        AutoGenerateColumns="false" runat="server">
                        <Columns>
                            <asp:BoundField Runat="server" DataField="ID"
                                HeaderText="ID" SortExpression="ID" >
                            </asp:BoundField>
                        </Columns>
                        <HeaderStyle />
                    </asp:GridView>                

                    <script type="text/javascript" 
                        src="~/../../Scripts/tablesorter_documentready.js"">
                    </script>

                </div>
            </div>
        </asp:Panel>
    </asp:Panel>
</asp:Content>

Site.Master站点管理员

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="PlisSmartSuiteLicenseToolsWebsite.SiteMaster" %>

<!DOCTYPE html>

<html lang="en">

<head runat="server">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title><%: Page.Title %> - PLIS License Management</title>

    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    <webopt:bundlereference runat="server" path="~/Content/css" />
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/CustomerStyle.css" rel="stylesheet" type="text/css" />



        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.1/css/theme.grey.min.css" integrity="sha256-oWElaGouUGQjjUj4NJOPJfu02uNGlUnwp+GrwEKTA44=" crossorigin="anonymous" />
        <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.1/js/jquery.tablesorter.min.js" integrity="sha256-uC1JMW5e1U5D28+mXFxzTz4SSMCywqhxQIodqLECnfU=" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.1/js/jquery.tablesorter.widgets.js" integrity="sha256-46l1q40VwOPnofvWNG4vQuFjxEnidAIBBn75kgKnI6c=" crossorigin="anonymous"></script>

</head>

Addingthe scripttags for JQuery and tablesorter above the script i'm importing works, but I want to avoid that.在我正在导入的脚本上方添加 JQuery 和 tablesorter 的脚本标签有效,但我想避免这种情况。

The console just prints that tablesorter() is not a function.控制台只是打印 tablesorter() 不是函数。

Note: it works on other pages.注意:它适用于其他页面。 Edit: I cut down the code for readability, it's way larger but the amount of div's are right.编辑:我减少了代码的可读性,它的方式更大,但 div 的数量是正确的。

Worth a look as it helped me with this issue: here值得一看,因为它帮助我解决了这个问题: 这里

Async postbacks from the update panel ruins event handlers when content is returned - the solution refreshes those so you can use them.当内容返回时,更新面板的异步回发会破坏事件处理程序 - 解决方案会刷新它们,以便您可以使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM