私はVS 2015を使用していて、新しいASP C#Webformsプロジェクトを開始しています。テンプレートにはScriptManagerが含まれています。問題は、コンテンツページでJQueryを動作させることができないことです。スタンドアローンのページでうまく動作します。私のコードを参照してください。ASP Webforms JQuery
おかげで、
マスターページのコードの下に
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="PayrollTimeManagement.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 %> - My ASP.NET Application</title>
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
<webopt:bundlereference runat="server" path="~/Content/css" />
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<script src="Scripts/jquery-ui-1.12.0/external/jquery/jquery.js"></script>
<script src="Scripts/jquery-ui-1.12.0/jquery-ui.js"></script>
<script src="Scripts/jquery-ui-1.12.0/jquery-ui.min.js"></script>
</head>
<body>
<form runat="server">
<asp:ScriptManager runat="server">
<Scripts>
<%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="respond" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" runat="server" href="~/">Application name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a runat="server" href="~/">Home</a></li>
<li><a runat="server" href="~/About">About</a></li>
<li><a runat="server" href="~/Contact">Contact</a></li>
</ul>
<p class="nav navbar-text navbar-right">Hello, <asp:LoginName runat="server" />!</p>
</div>
</div>
</div>
<div class="container body-content">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
<hr />
<footer>
<p>© <%: DateTime.Now.Year %> - My ASP.NET Application</p>
</footer>
</div>
</form>
</body>
</html>
は私のコンテンツページのコードです - コードは動作しません。私が、両方の私のマスターページとコンテンツページでjQueryのにrefは、
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="PayrollTimeManagement.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<script src="Scripts/jquery-ui-1.12.0/external/jquery/jquery.js"></script>
<script src="Scripts/jquery-ui-1.12.0/jquery-ui.js"></script>
<script src="Scripts/jquery-ui-1.12.0/jquery-ui.min.js"></script>
<script src="Scripts/select2.js"></script>
<link href="Content/css/select2.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function() { $("#DropDownList1").select2(); });
</script>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>aawe3wrw4t34t</asp:ListItem>
<asp:ListItem>ss</asp:ListItem>
<asp:ListItem>ff</asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem>rye</asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem>43t5</asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem>rey</asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</asp:Content>
あなたのコンテンツページはどこですか?なぜContentPlaceholderとMasterPageFileを使用しないのですか? – toha