Lak Ranasinghe
Lak Ranasinghe

Reputation: 240

System.Web.UI.HtmlControls.HtmlGenericControl replacement in .Net 4.6.1

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");                        

Upvotes: 0

Views: 6673

Answers (2)

Carl in 't Veld
Carl in 't Veld

Reputation: 1503

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!

Upvotes: 0

Lak Ranasinghe
Lak Ranasinghe

Reputation: 240

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.

Upvotes: 1

Related Questions