Error on adding <script> to master page

亡梦爱人 提交于 2020-01-07 07:09:05

问题


I have a Master page that have these ContentPlaceHolder:

<asp:ContentPlaceHolder ID="title" runat="server">
    </asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="contentTitle" runat="server" ></asp:ContentPlaceHolder>
        <asp:ContentPlaceHolder ID="content" runat="server">
        </asp:ContentPlaceHolder>

when I add these codes for jquery in<head> part of master page:

<script type="text/javascript" src="script/jquery-2.0.1.min.js" />
<link href="script/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="script/jquery.contextMenu.js" />

and create new aspx file that use that master page ;

<%@ Page Title="" Language="C#" MasterPageFile="~/Default.Master"    AutoEventWireup="true" CodeBehind="Bed.aspx.cs" Inherits="Zhotel.Lists.Bed" %>
<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentTitle" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="content" runat="server">
</asp:Content>

when I want to view Design part of file it show me this error:

and when I remove script tags then no more this error occurs.

How can I use script tag that this error not shown?


回答1:


Add </script> to end of jquery definition, like this:

<script src="script/jquery-2.0.1.min.js" type="text/javascript"></script>
<script src="script/jquery.contextMenu.js" type="text/javascript"></script>  



回答2:


place your scripts outside of contentplaceholder 'title' in head section and make sure that your page has correct reference to your masterpage and also make sure that you are placing the contentplaceholders in their appropriate places



来源:https://stackoverflow.com/questions/17010556/error-on-adding-script-to-master-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!