如何在母版页的内容页中包含外部javascript文件?
问题描述:
尊敬的先生/女士
我想通过外部javascript文件对主页的内容页面进行javascript验证.
我已经尝试过,但是无法包含.js文件.如果有其他方法,请帮助我.
关于问候
Ranjan Pati
Dear Sir/Mam
I want to give javascript validation to a content page of a master page from an external javascript file.
I have tried but it is unable to include the .js file. Please help me if there is any other way.
With regards
Ranjan Pati
答
有一个帖子 ^ ]描述了母版页和样式表的解决方案. JavaScript可能是相同的解决方案,使用它可以使JS可用于所有内容页面.
如果要在内容页面上使用JS just ,请确保将其放入ContentPlaceholder容器中,紧接在结束标记之前.如果采用这种方法,则无需修改Site.Master.
如果仍然遇到问题,请确保尝试使用良好的Shift + Refresh(F5)
在页面上,因为您可能只是看到缓存的副本.
干杯.
There is a post here[^] which describes a solution for master pages and style sheets. JavaScript could be the same solution and using this would make the JS available to all content pages.
If you''re wanting the JS just on the content page, make sure you put it inside the ContentPlaceholder container, right before your closing tag. You won''t need to modify your Site.Master if you take this approach.
If you''re still having trouble, make sure you try a good Shift+Refresh (F5)
on the page as you might just be seeing the cached copy.
Cheers.
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<!-- adding external script file-->
<script language="javascript" type="text/javascript" src="JScript.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>