title: ASP.NET - Parse / Query HTML Before Transmission and Insert CSS Class References
body: <p>As a web developer I feel too much of my time is spent on CSS. I am trying to come up with a solution where I can write <strong>re-usable CSS</strong> i.e. classes and reference these classes in the HTML without additional code in ASPX or ASCX files etc. or code-behind files. I want an <strong>intermediary</strong> which links up HTML elements with CSS classes.</p>
  
  <p>What I want to achieve:</p>
  
  <ul>
  <li>Modify HTML immediately before transmission</li>
  <li>Select elements in the HTML</li>
  <li>Based on rules defined elsewhere (e.g. in a text file relating to
  the page currently being processed):</li>
  <li>Add a CSS class reference to multiple HTML elements</li>
  <li>Add <strong>multiple CSS class references</strong> to a single HTML element</li>
  </ul>
  
  <p>How I envisage this working:</p>
  
  <ol>
  <li>Extend ASP.NET functions which generate final HTML</li>
  <li>Grab all the HTML as a string</li>
  <li>Pass the string into a contructor for an object with querying (e.g. XPATH) methods</li>
  <li>Go through list of global rules e.g. for child <code>ul</code> of first <code>div</code> then <code>class = "navigation"</code></li>
  <li>Go through list of page specific rules e.g. for child <code>ul</code> of first <code>div</code> then <code>class &amp;= " home"</code></li>
  <li>Get processed HTML from object e.g. obj.ToString</li>
  <li>ASP.NET to resume page generation using processed HTML</li>
  </ol>
  
  <p><strong>So what I need to know is:</strong></p>
  
  <ol>
  <li>Where / how can I <strong>extend ASP.NET page generation</strong> functions (to get all HTML of page)</li>
  <li>What classes have <strong>element / node querying methods</strong> and access to attributes</li>
  </ol>
  
  <p>Thanks for your help in advance.</p>
  
  <p>P.S. I am developing ASP.NET web forms websites with VB.net code-behinds running on ISS 7</p>