title: ASP.NET: generate property value when adding control to page
body: <p>Context: ASP.NET 3.5 / C#</p>
  
  <p>Hi,</p>
  
  <p>I created a user control</p>
  
  <pre><code>public partial class MyControl : UserControl
  {
      // EDIT: example first used "UniqueId" as property name, which was wrong.
      public Guid MyId { get; set; }
      // ...
  }
  </code></pre>
  
  <p>and this example usage</p>
  
  <pre><code>&lt;uc1:MyControl 
      ID="myControl" 
      MyId="443CBF34-F75F-11DD-BE2F-68C555D89123"
      runat="server" /&gt;
  </code></pre>
  
  <p>Steps:</p>
  
  <ul>
  <li>Add this control to a web form (aspx)</li>
  </ul>
  
  <p>Expected result:</p>
  
  <ul>
  <li>the HTML for the user control is added, a unique value (corresponding to Guid.NewGuid()) for MyId is set in the ASPX HTML at design-time as the MyId attribute value.</li>
  </ul>
  
  <p>Actual result:</p>
  
  <ul>
  <li>the HTML for the user control is added, a unique value for MyId is not set in the HTML at design time for the MyId  Attribute value.</li>
  </ul>
  
  <p>If this is not possible:</p>
  
  <ul>
  <li>Workaround 1: Would it be possible to achieve this using a server control? How?</li>
  <li>Workaround 2: is it possible to achieve this using a UserControl design-mode task?</li>
  </ul>
  
  <p>Clarification: </p>
  
  <ul>
  <li>persisting the property value is <strong>not</strong> an issue, since it never changes for a control intance and is automatically set by ASP.NET through the control declaration in the aspx page.</li>
  <li>the MyId attribute does not need to be rendered at runtime.</li>
  </ul>
  
  <p>Gr B!</p>