title: ASP: runat=server for dynamic control
body: <p>In the Page_Load method I create a couple of controls, based on various conditions. I would like to register server side code with those controls. However, for the last part I need to declare my controls as server controls. This is normally done by runat=server, but I don't know how to set this attribute in the C# code. myControl.Attributes.Add("runat", "server") does not do the trick. This one works, meaning that the "test" method is called when I click on it:</p>
  
  <pre><code>&lt;asp:LinkButton ID="LinkButton1" runat="server" OnClick="test"&gt;testtext&lt;/asp:LinkButton&gt;
  </code></pre>
  
  <p>This one does not work:</p>
  
  <pre><code>            LinkButton lb = new LinkButton();
              lb.ID = "LinkButton1";
              lb.OnClientClick = "test";
              lb.Text = "testtext";
              lb.Attributes.Add("runat", "server");
  </code></pre>
  
  <p>I can click on it, and the page is loaded, but the test-method is not called. </p>
  
  <p>Any hints?</p>