title: Adding styles and scripts to ASP.NET web controls (ascx) without repeating inclusion directives
body: <p>Consider to develop a web control (ASP.NET). What you would really like to do is styling and developing this control in a very good way, here's a very good way to do this (this is how I would like to do, further in this question I will explain why I cannot do this).</p>
  
  <h2>A programmatic approach</h2>
  
  <p>1) I create my control in a separate folder called <code>WebControls</code> and I name it (for example) <code>MyWebControl</code>. I will have these files: <code>MyWebControl.ascx</code> and <code>MyWebControl.ascx.cs</code>.</p>
  
  <p>2) Given that my control is a complex control I associate a style and a dynamic client behavior referencing, in the control html, a css stylesheet called <code>MyWebControl.ascx.css</code> and a javascript file called <code>MyWebControl.ascx.js</code>.</p>
  
  <p>3) In my control I do the following:</p>
  
  <pre><code>&lt;%@ Control Language="C#" 
              AutoEventWireup="true" 
              CodeFile="MyWebControl.ascx.cs" 
              Inherits="MyApp.WebControls.MyWebControl" %&gt;
  
  &lt;link href="MyWebControl.ascx.css" rel="stylesheet" type="text/css" /&gt;
  &lt;script src="MyWebControl.ascx.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;div&gt;
  ...
  &lt;/div&gt;
  </code></pre>
  
  <p>This is it!</p>
  
  <h2>The problem</h2>
  
  <p>Well there is a problem in this thing: when my control is rendered, and in a page there is more than one of this control of mine, I get the links to the css and js file duplicated or even repeated more than once.</p>
  
  <p>How to link an external stylesheet/javascript file in my control without occurring in this bad stuff?</p>
  
  <h2>EDIT</h2>
  
  <p>OK, after looking a bit, with the help of others here in the community, I could understand that <code>Page.ClientScript</code> is what comes to the rescue.</p>
  
  <p>However, there are a lot of functionality for a script to be registered... can you tell the difference among these?</p>
  
  <p>1) <code>Page.ClientScript.IsClientScriptBlockRegistered</code></p>
  
  <p>2) <code>Page.ClientScript.IsClientScriptIncludeRegistered</code></p>
  
  <p>3) <code>Page.ClientScript.IsOnSubmitStatementRegistered</code></p>
  
  <p>4) <code>Page.ClientScript.IsStartupScriptRegistered</code></p>
  
  <p>And the corresponding set methods?</p>
  
  <p>1) <code>Page.ClientScript.RegisterClientScriptBlock</code></p>
  
  <p>2) <code>Page.ClientScript.RegisterClientScriptInclude</code></p>
  
  <p>3) <code>Page.ClientScript.RegisterOnSubmitStatement</code></p>
  
  <p>4) <code>Page.ClientScript.RegisterStartupScript</code></p>
  
  <p>Furthermore: can this be applied to javascript and css too?</p>
  
  <p>Thankyou</p>