0

What is the HtmlGenericControl(String) equivalent class in .Net framework 4.6.1 that could be used to generate HTML content?

We are upgrading .Net framework from 4.0 to 4.6.1 for an ASP.Net web application. We have replaced System.Web.UI.HtmlControls.HtmlGenericControl with System.Web.UI.HtmlControls.HtmlElement in all classes but it resulted with the following error message.

The base class includes the field 'html', but its type (System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlElement)

enter image description here

The fix is also explained here.

The issue we have is that application also use HtmlGenericControl(String) constructor and replaced HtmlElement() class doesnt have a constructor that take string parameter to specify tag.

Example:

var h3Header = new HTMLGenericControl("h3");                        

Looking for something like this:

var h3Header = new HtmlElement("h3");                        
MuKa
  • 165
  • 2
  • 2
  • 13
Lak Ranasinghe
  • 240
  • 4
  • 13
  • May i know why did you replace `HtmlGenericControl` with `HtmlElement`? `HtmlGenericControl` works fine .Net framework 4.6.1. The link you have mentioned has the issue where 'HtmlElement' was getting converted to 'HtmlGenericControl' during migration. Not the other way round. – Boney Nov 14 '16 at 06:09
  • Thanks @Boney for the response. I get above error at run time (refer to the screenshot above) after upgraded to .Net framework 4.6.1. I recompiled the Designer.cs files by updating HTML code and that only replaced HTMLGenericControl to HTMLElement. Above error disapeared from login page so I applied the change (rename HTMLGenericControl to HTMLElement) in all the affected files. – Lak Ranasinghe Nov 14 '16 at 12:57
  • @Boney, You are right. The link listed the error other way around because he was getting the error after he made the changes (recompiling .cs files after updating HTML code) and he has missed updating the targetFramework to 4.5 in web.config file so it was trying to run on .net framework 4.0. – Lak Ranasinghe Nov 14 '16 at 13:06

2 Answers2

1

We ended up using 'HTMLGenericControl()' and change web.config targetFramework to 4.0 instead of 4.6.1.

<compilation debug="true" targetFramework="4.0">

This allowed us to use .Net framework 4.6.1 compiled libraries in web project while using existing 'HTMLGenericControl()' code.

Lak Ranasinghe
  • 240
  • 4
  • 13
0

We stumbled upon this issue while migrating from 3.5 to 4.5. Our compilation tag is configured as follows:

<compilation debug="false" batch="false" targetFramework="4.5">

We tackled the error message in another way:

The base class includes the field 'html', but its type (System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlElement)

You need to replace id="html" in the following:

<html xmlns="http://www.w3.org/1999/xhtml" runat="server" id="html">

Becomes:

<html xmlns="http://www.w3.org/1999/xhtml" runat="server" id="randomidentifier">

Thus the field 'html' in the base class was conflicting with the control generated by the ASP.NET runtime based on the id attribute!

Carl in 't Veld
  • 1,363
  • 2
  • 14
  • 29