title: How do I add an expando attribute to a user control?
body: <p>I am building in some custom javascript functionality in an existing ASP.NET usercontrol. The usercontrol needs to know about a property of the control it is nested in. So, I ended up opting for using an expando attribute rather than a global javascript variable like this:</p>
  
  <pre><code>Page.ClientScript.RegisterExpandoAttribute(Me.ClientID, "validatorsenabled", Me.ValidatorsEnabled)
  </code></pre>
  
  <p>However, although the expando is output to the client properly, the usercontrol itself doesn't have a corresponding element in HTML. So, the following JavaScript that is autogenerated by ASP.NET gets an "object is null" error:</p>
  
  <pre><code>var ctl00_MainContentHolder_Payment_CreditCardInput1 = document.all ? document.all["ctl00_MainContentHolder_Payment_CreditCardInput1"] : document.getElementById("ctl00_MainContentHolder_Payment_CreditCardInput1");
  ctl00_MainContentHolder_Payment_CreditCardInput1.validatorsenabled = "False";
  </code></pre>
  
  <p>I did a little investigating and discovered <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.iwebpart.aspx" rel="noreferrer">this page</a> indicating that implementing the IWebPart interface might do it, but I tried with no luck.</p>
  
  <p>Is there any way to make a usercontrol output a tag like a server control? Or is the only option converting the entire thing to a server control (which goes against the grain of the website design in this case)?</p>
  
  <p>I am open to other suggestions for declaring a shared JavaScript property in a user control if anyone has any other ideas.</p>