title: working around ASP.NET 3.5 control ID generation: Postback events when the controls are created in a different order on subsequent postbacks
body: <p>I'm working on a commenting system for a website and on each postback a page generates a user control (called ucComment) for every single comment in the database that pertains to this page.  Each ucComment has a Respond button that allows you to respond to each individual comment.</p>
  
  <p>I was having a problem with the Respond button not doing anything when I finally realized that every time a new comment was created, the next postback it would offset all the page's control IDs.  In other words, when I click on ctl00_Content_ctl00_ctl01_ctl0<strong>7</strong>_lbtnRespond, that control would actually be generated as ctl00_Content_ctl00_ctl01_ctl0<strong>8</strong>_lbtnRespond on the next postback.  So the event associated with ctl07 would simply not happen.  </p>
  
  <p>While poking around on the web, I read about overriding the ClientID. I thought if I could name the controls the way I wanted to, I could circumvent my problem.
  <a href="http://west-wind.com/Weblog/posts/4605.aspx" rel="nofollow noreferrer">http://west-wind.com/Weblog/posts/4605.aspx</a>
  It looked like a great hack but it doesn't fire events because of the disparity between the generated ID on the page and how the ID was represented in the control tree.  </p>
  
  <p>there's even a guy who derived from MasterPage to change the way that the control tree works to get the above hack to work for postbacks:
  <a href="http://www.netquarry.com/index.php/2009/03/master-pages-ajax-and-javascript-10292/" rel="nofollow noreferrer">http://www.netquarry.com/index.php/2009/03/master-pages-ajax-and-javascript-10292/</a>
  but i fear that there may be untold repercussions.</p>
  
  <p>What should I do to get my commenting system working such that I can respond to a specific comment and have the respond event still fire even if the control is renamed on that postback?</p>