Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd a control to the page header in ASP.NET
    text
    copied!<p>I'm creating a custom script control in ASP.NET</p> <p>The purpose of the control is simply a server variant of the tag, used to load javascript files The main purpose of this control however is to combine multiple scripts into one response so on the client side they see something like tag for each location, so all scripts registered in the DocumentTop location will be combined into a single tag with the exception of the location "inline", all inline scripts are rendered individually where they exist in the markup I have also created an httphandler, js.ashx, that does the actual combining of the scripts</p> <p>Everything is working fine except for the "Head" location, for the two document locations i simply use the ClientScriptManager during prerender but for the Head location i have tried the following code during pre render</p> <pre><code>var scriptControl = new HtmlGenericControl("script"); scriptControl.Attributes["language"] = "javascript"; scriptControl.Attributes["type"] = "text/javascript"; scriptControl.Attributes["src"] = src; Page.Header.Controls.Add(scriptControl); </code></pre> <p>and I get the following error: The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.</p> <p>does anyone know how add a control to the page header from within a custom control?</p> <p>Incidentally, the control is used on a content page that has two nested masters and also has a ScriptManager registered on the root master. The project is an asp.net 3.5 web application project</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload