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



我目前正在尝试在我的子页面中使用 JS 函数,该函数已加载到母版页中,但它不起作用。

在调用它们之前,我尝试再次添加脚本,这有效,但这是不必要的,因为它应该已经加载了。

管理密钥.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>

网站.大师

<%@ 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>

在我正在导入的脚本上方添加 JQuery 和表排序器的脚本标记是有效的,但我想避免这种情况。

控制台只是打印tablesorter((不是一个函数。

注意:它适用于其他页面。 编辑:我削减了代码以提高可读性,它更大,但div的数量是正确的。

值得一看,因为它帮助我解决了这个问题:这里

返回内容时,来自更新面板的异步回发会破坏事件处理程序 - 解决方案会刷新这些处理程序,以便您可以使用它们。

最新更新