首先head标签上添加runat="server"。
protected void Page_Load(object sender, EventArgs e) { Page.Title = "标题"; //Description HtmlMeta desc = new HtmlMeta(); desc.Name = "Description"; desc.Content = "描述"; Page.Header.Controls.Add(desc); //Keyword HtmlMeta keywords = new HtmlMeta(); keywords.Name = "keywords"; keywords.Content = "关键字"; Page.Header.Controls.Add(keywords); //js HtmlGenericControl autoCompleteScript = new HtmlGenericControl("script"); autoCompleteScript.Attributes.Add("type", "text/javascript"); autoCompleteScript.Attributes.Add("src", "/js/autocomplete/jquery.autocomplete.js"); Page.Header.Controls.Add(autoCompleteScript); //css HtmlLink autoCompleteCss = new HtmlLink(); autoCompleteCss.Href = "/js/autocomplete/jquery.autocomplete.css"; autoCompleteCss.Attributes.Add("rel", "stylesheet"); autoCompleteCss.Attributes.Add("type", "text/css"); Page.Header.Controls.Add(autoCompleteCss); }