我可以使用ASP在每个内容页面包含不同的javascript/css文件。净WebForms大师页面?

时间:2023-01-10 15:56:38

I have several Content Pages using the same Master Page, that don't all need the same javascript and css files included in the <head> tag.

我有几个使用相同主页面的内容页面,它们不需要包含在标记中的相同的javascript和css文件。

Is it possible to change the contents of the <head> tag from the Content Pages?

是否可以从内容页面中更改标签的内容?

2 个解决方案

#1


3  

it is, but I recommend doing it a bit different. I place a content place holder right above the close body tag. Then I populate the required JS scripts per content page. This will allow you to place the scripts at the bottom, but you could also do the same with the placeholder in the header.

是的,但是我建议你做一些不同的事情。我将内容放置在靠近body标签的地方。然后,我在每个内容页面填充所需的JS脚本。这将允许您将脚本放在底部,但是您也可以对页眉中的占位符执行相同的操作。

You can also do so programmatically:

您也可以通过编程方式这样做:

HtmlGenericControl js = new HtmlGenericControl("script");
js.Attributes["type"] = "text/javascript";
js.Attributes["src"] = "jscript/jquery.js";
Page.Header.Controls.Add(js);

#2


0  

Put a Placeholder control in the head and you should be able to use that in the content pages.

在头部放置一个占位符控件,您应该能够在内容页面中使用它。

#1


3  

it is, but I recommend doing it a bit different. I place a content place holder right above the close body tag. Then I populate the required JS scripts per content page. This will allow you to place the scripts at the bottom, but you could also do the same with the placeholder in the header.

是的,但是我建议你做一些不同的事情。我将内容放置在靠近body标签的地方。然后,我在每个内容页面填充所需的JS脚本。这将允许您将脚本放在底部,但是您也可以对页眉中的占位符执行相同的操作。

You can also do so programmatically:

您也可以通过编程方式这样做:

HtmlGenericControl js = new HtmlGenericControl("script");
js.Attributes["type"] = "text/javascript";
js.Attributes["src"] = "jscript/jquery.js";
Page.Header.Controls.Add(js);

#2


0  

Put a Placeholder control in the head and you should be able to use that in the content pages.

在头部放置一个占位符控件,您应该能够在内容页面中使用它。