title: Adding attribute to html tag via code-behind results in error type (System.Web.UI.HtmlControls.HtmlElement) is not compatible
body: <p>When I try to add an attribute to my html tag in my masterpage:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" id="primtag" runat="server"&gt;
  </code></pre>
  
  <p>like so in code behind:</p>
  
  <pre><code>prmimaryhtml_tag.Attributes.Add("lang", "en")
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Parser Error
  
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 
  
  Parser Error Message: The base class includes the field 'primtag', but its type (System.Web.UI.HtmlControls.HtmlElement) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl).
  
  Source Error: 
  
  
  Line 4:  
  Line 5:  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  Line 6:  &lt;html xmlns="http://www.w3.org/1999/xhtml" id="primtag" runat="server"&gt;
  Line 7:  &lt;head id="Head1" runat="server"&gt;
  Line 8:      &lt;title&gt;&lt;/title&gt;
  
  Source File: /main.master    Line: 6 
  </code></pre>
  
  <p>I also checked <code>main.master.designer.vb</code> and it holds this line:    </p>
  
  <pre><code>Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement
  </code></pre>
  
  <p>Now, the weirdest thing is: this code works correct on my local machine, but not on my production server. I don't know what's causing this different behavior either.</p>
  
  <p>I also looked at this post: <a href="https://stackoverflow.com/questions/6024378/set-pages-main-html-tag-in-c-sharp/6024448">set pages main html tag in c#</a></p>
  
  <p><strong>UPDATE</strong>
  When my situation is as follows:</p>
  
  <p><code>main.master.designer.vb</code></p>
  
  <pre><code> Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement
  </code></pre>
  
  <p><code>main.master.aspx</code></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" ID="primtag" runat="server"&gt;
  </code></pre>
  
  <p><code>main.master.aspx.vb</code></p>
  
  <p>commented this line:</p>
  
  <pre><code>'primtag.Attributes.Add
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Parser Error
  
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 
  
  Parser Error Message: The base class includes the field 'primtag', but its type (System.Web.UI.HtmlControls.HtmlElement) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl).
  
  Source Error: 
  
  
  Line 4:  
  Line 5:  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  Line 6:  &lt;html xmlns="http://www.w3.org/1999/xhtml" ID="primtag" runat="server"&gt;
  Line 7:  &lt;head id="Head1" runat="server"&gt;
  Line 8:      &lt;title&gt;&lt;/title&gt;
  </code></pre>
  
  <p>After that I tried changing that line in the main.master.designer.vb file from <code>Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlElement</code> to <code>Protected WithEvents primtag As Global.System.Web.UI.HtmlControls.HtmlGenericControl</code> On the production server I get:</p>
  
  <p><code>Object reference not set to an instance of an object.</code></p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>It may have something to do with compilation of my solution, I also checked these posts:</p>
  
  <pre><code>http://briancaos.wordpress.com/2013/08/07/system-web-ui-htmlcontrols-htmliframe-is-not-compatible-with-the-type-of-control-system-web-ui-htmlcontrols-htmlgenericcontrol/
  https://connect.microsoft.com/VisualStudio/feedback/details/736011/iframe-parser-error
  http://forums.asp.net/t/1884696.aspx?help+required+with+iframes+on+aspx
  http://support.microsoft.com/kb/941824
  http://forums.asp.net/t/1686949.aspx
  </code></pre>
  
  <p>I then check my IIS7.5 setting on local machine, there the application pool was set to ASP.NET4.0, same as on my production server.
  My target framework compilation in Visual Studio is set to .NET Framework 4.5.</p>
  
  <p>Hopefully this provides more insights in getting this to work. Please help :)</p>