i have an master page and i use it in a aspx page, when i press a button i want to load some javascript files and css files and load a user control to my page, so i am doing this:
ContentPlaceHolder headContent = (ContentPlaceHolder)this.Page.Master.FindControl("headerContent");
HtmlGenericControl control = new HtmlGenericControl();
control.TagName = "script";
control.Attributes.Add("type", "text/javascript");
control.Attributes.Add("src", ResolveUrl("Scripts/jquery-1.9.1.min.js"));
headContent.Controls.Add(control);
all right, but if i load some plugins they dont work. im loading this in user control oninit function.
i have a placeholder in master page head.
Instead of manually creating script tag, just call the useful RegisterClientScriptInclude . It is easier. So change your code to following:
Page.ClientScript.RegisterClientScriptInclude("jQuery", "Scripts/jquery-1.9.1.min.js");
or If your going to resolve url, do this:
Page.ClientScript.RegisterClientScriptInclude("jQuery", ResolveUrl("Scripts/jquery-1.9.1.min.js"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.