A CodeBehind error with User Controls

by Terry 6/11/2008 3:29:00 PM

I am updating a website for my project at work. It was a .Net 1.1 site converted to a .Net 2.0 site. We are adding some new user controls to the site. I implemented one of those controls on a new page and generated a runtime error like this:

"The base class includes the field 'WebUserControl1', but its type (common_WebUserControl) is not compatible with the type of control (ASP.common_webusercontrol_ascx)"

Hunting around with Google turned up several possibilities, but none helped until I found this link, http://forums.asp.net/t/960707.aspx. A post by ‘Maduka’ suggested changing the Codefile attribute of the page to CodeBehind. This worked in my case. It works the other way too. Change the control’s CodeBehind property to CodeFile.

Without digging deep, I would presume that CodeFile is the .Net 2.0+ code behind method, as this is the default value for the new user controls. So, in our implementation, we are changing pages that use the new controls to use the CodeFile attribute instead of CodeBehind. I am not sure which is best practice, but this is what works for me. Your mileage may vary.

And, it turns out I may have this backward. Reading the posts a bit more indicates that CodeBehind is the new model. I will need to look at this more closely. I am hoping to update the site to .Net 3.5 by the end of the year, and I would like to clean this stuff up.

Currently rated 1.5 by 111 people

  • Currently 1.459461/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Coding Practices | computing

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About Terry Losansky

Terry Dee Losansky

I am a software architect, actively practice and teach martial arts and live in Snoqualmie, Washington. I have an amazing daughter who is the jewel of my life.

E-mail me Send mail
Terry's Facebook profile

Calendar

<<  September 2018  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2018

Sign in