title: Register Startup Script Control
body: <p>I am looking to make a web control where I can register client startup scripts inline with my aspx because I hate registering in the codebehind!</p>
  <p>An example of what I have so far:</p>
  <pre><code>&lt;Ben:StartupScript runat=&quot;server&quot;&gt;
  
      var form = document.getElementById(&quot;&lt;% =form1.ClientID %&gt;&quot;);
  
  &lt;/Ben:StartupScript&gt;
  </code></pre>
  <p>Currently, I am overriding the <code>OnPreRender</code> method of the control, rendering the contents of the control to a string and then manually registering that string as a  startup script using <code>ClientScript.RegisterStartupScript</code> on the <code>Page</code>. I also override the <code>Render</code> method in order not to render the control. I should also note that I have the <code>ParseChildren</code> attribute set to <code>false</code> and the <code>PersistChildren</code> attribute set to <code>true</code>.</p>
  <p>All seems to be working well, but my control allows other web controls inside it (such as Button). Apart from being unintuitive, this can result in runtime errors. I would love to be able to clear the controls but this is impossible given the <code>&lt;% ... %&gt;</code> code block.</p>
  <p>So, is it possible to prevent developers from embedding child controls whilst still allowing code blocks?</p>
  <p>Also, is this idea any good or is it fundamentally flawed? Lol.</p>
  <p>Thanks a bunch,</p>
  <p>Ben</p>