Cof*_*fee 4 javascript c# asp.net
这可能是一个新手问题,但我对asp.net和C#等很新.
我正在使用ASP.net网站,我很好奇它的结构(在自动创建一个Web项目之后),特别是以下内容:
我在Default.aspx中看到,我有一个这样的标签:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>**strong text**
Run Code Online (Sandbox Code Playgroud)
但是在Site.master中,我有这个:
<head runat="server">
*etc*
</head>
Run Code Online (Sandbox Code Playgroud)
那么,如果我想在页面加载时包含要运行的JavaScript代码,我会在哪里放置代码?
我相信你可以把你的代码放在其中任何一个.第一个用于添加所有内容页面(使用此母版页文件)使用的代码或脚本,而第二个用于添加内容页面中的脚本或代码(仅应用于此特定页面)
//in the Master page, the content here is used by all content pages
<head runat="server">
*etc*
</head>
Run Code Online (Sandbox Code Playgroud)
和
//this is specific to the content page that use it. This section needs to be supplied in content pages
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
该部分需要在每个内容页面中提供,并且它将独占于该页面 - 其他页面不能使用该部分中的脚本
asp:Content ID =“ HeaderContent”是一个内容区域。生成标记时,该标记中的所有内容都会嵌入到母版页中关联的ContentPlaceHolder中。
head是标准的html标记,指示页面head元素。通常,HeadContent占位符在母版页的head标记内。