Can I Include different javascript/css files per Content Page using ASP.NET WebForms Master Pages?

*爱你&永不变心* 提交于 2019-12-07 10:36:10

问题


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.

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


回答1:


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.

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:


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



来源:https://stackoverflow.com/questions/3338022/can-i-include-different-javascript-css-files-per-content-page-using-asp-net-webf

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