0

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>
9
  • I'd love an explanation for the down votes. I ran into this problem and searched stack overflow and there is not an existing question on this already. The answer is not intuitive and I thought It was worth sharing for people in the future to find. Commented May 10, 2018 at 16:36
  • 2
    I'd guess the lack of code is the reason. Commented May 10, 2018 at 16:37
  • @juharr Should I really have posted an entire .aspx page for the question? That seems like a lot of noise when the code is clear in the answer. I could put the one line that the problem is occurring on into the question, but at the time of my problem at least I had no idea where the problem was. The error indicates line 1 but it is not on line one. Commented May 10, 2018 at 16:41
  • No, but at least the line the problem occurs on. Or if that's not the actual problem, then a minimal set of code that reproduces the problem. And just because you have it in the answer doesn't mean it shouldn't be in the question. Think about if you didn't have the answer, then no one would have known. Commented May 10, 2018 at 16:42
  • 1
    @Kyle Even a self-answered question is supposed to meet all guidelines for asking a good question. Sometimes (often) more answers show up. It would be hard for readers to pick out the one that supplies the missing pieces. Commented May 10, 2018 at 16:49

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.