Kyle
Kyle

Reputation: 33739

CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.HtmlControls.HtmlGenericControl'

Using asp.net webforms I receive this error on line 1:

CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.HtmlControls.HtmlGenericControl'

<h2 id="Title" ClientIDMode="Static" runat="server">Evaluations</h2>

Upvotes: 0

Views: 2404

Answers (1)

Kyle
Kyle

Reputation: 33739

You can't have ID="Title" with runat="server".

Changing the ID to anything else, like Title1 or PageTitle, and the page compiles and runs fine again.

<h2 id="Title" ClientIDMode="Static" runat="server">Evaluations</h2>

To:

<h2 id="PageTitle" ClientIDMode="Static" runat="server">Evaluations</h2>

Fixes the problem.

This problem is caused because the partial class that gets generated hides the existing Title on the control.

Upvotes: 2

Related Questions