Request a topic or
contact an Arke consultant
404-812-3123
CodeFile and CodeBehind are not the same thing

Arke Systems Blog

Useful technical and business information straight from Arke.

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Archive

Authors

Disclaimer

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

© Copyright 2021

CodeFile and CodeBehind are not the same thing

A user control with a CodeFile attribute:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="controlname.ascx.cs" Inherits="mynamespace.controls.controlname" %>

will sometimes result in the error message:

"The base class includes the field 'ControlID1', but its type (mynamespace.controls.controlname) is not compatible with the type of control (ASP.controls_controlname_ascx)"

Switching to

CodeBehind="controlname.ascx.cs"

fixes it right up.

Thank god for forums.

Behind the scenes, per stackoverflow, CodeBehind only works with a precompiled dll while CodeFile can compile on the fly.  I assume there is some problem with the compile on the fly feature and custom controls, perhaps when they are registered in web.config, perhaps when they are used from master pages, I don’t know… I just know it doesn’t reliably work, and it can be a real headache figuring out why.


Posted by David Eison on Friday, August 13, 2010 6:29 PM
Permalink | Comments (0) | Post RSSRSS comment feed