The Confusing "Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox'" Compilation Error

Published 26 January 07 04:48 PM | Scott Mitchell

When building an ASP.NET 2.0 application in Visual Studio 2005, I received the following error: “Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox'”. No line number, no source page informing me where to begin my search. And it had been a while since my last build so there was a lot of code and markup that could be the source of the problem.

A quick Google search turned up this entry by Sam Judson:

Strange ASP.NET 2.0 Error

While developing a new web site using ASP.Net 2.0 recently I came across this strange error on compilation.

    Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox'

It took my ages to work out what the hell was the problem, which string was it trying to convert?

The problem occurred because of the new Page.Title property. I had a TextBox whose ID was also set to Title. It was therefore trying to convert the string in the Page declaration into a textbox - not gonna work! This Title property is new for ASP.Net 2.0 so you might want to watch that one in your apps.

And that was the cause of my problem, a TextBox with an ID of Title. Once the ID was changed to something else, the project compiled without error. For more on the Page.Title property new to ASP.NET 2.0, see Dynamically Setting the Page's Title in ASP.NET 2.0.

Filed under:

Comments

# Andrew said on November 5, 2010 08:10 AM:

Thanks, I never would have figured this out otherwise...you saved me a lot of time.

# Austin said on February 22, 2011 08:13 PM:

I can't believe that was the problem... runtime error message highlights the first line! Completely confusing, this was great. Thanks.

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.