Compilation of UserControls

N

Nathan Sokalski

In several of my UserControls I add properties. If I access these properties
in the CodeBehind of the pages that use the controls, I recieve an error
when compiling. The reason for this is because the compiler tries to compile
the pages that use the UserControls before compiling the UserControls, and
therefore does not know that the property exists when compiling. The only
way around this that I have found is to use the CType() function as follows:

CType(MyUserCtrlInstance, MyUserCtrlClass).AddedProperty

instead of:

MyUserCtrlInstance.AddedProperty

Even though this works, it is a lot of extra CType() functions that would
not be necessary if I could simply have my UserControls compiled first. Is
there any way to make the compiler look at my UserControls first without
putting them in a separate assembly? Thanks.
 
G

Gaurav Vaish \(MasterGaurav\)

Well, if the UserControls are not compiled (or at least resolved properly),
the classes that depend on them would not compile.

And btw, what is the datatype of MyUserCtrlInstance? Is it simply
UserControl --- if so, yes, you are already in trouble.
 
G

Guest

Out of curiuosity nathan, What langauge are you using
C#? or VB.NET
And what version of .NET are you using? 1.x or 2.0 ?
I put controls in my App_Code all the time for quicker testing and
development and this usually works fine for me.
 
M

Mark Rae

Out of curiuosity nathan, What langauge are you using
C#? or VB.NET

Fairly obviously VB.NET, judging by the fact that he's talking about
CType(), and the fact that he's crossposted, among others, to
microsoft.public.dotnet.languages.vb
 
C

Corey B

Nathan said:
In several of my UserControls I add properties. If I access these properties
in the CodeBehind of the pages that use the controls, I recieve an error
when compiling. The reason for this is because the compiler tries to compile
the pages that use the UserControls before compiling the UserControls, and
therefore does not know that the property exists when compiling. The only
way around this that I have found is to use the CType() function as follows:

CType(MyUserCtrlInstance, MyUserCtrlClass).AddedProperty

instead of:

MyUserCtrlInstance.AddedProperty

Even though this works, it is a lot of extra CType() functions that would
not be necessary if I could simply have my UserControls compiled first. Is
there any way to make the compiler look at my UserControls first without
putting them in a separate assembly? Thanks.

Nathan, have you tried the Build | Rebuild Web Site menu item in VS.NET
2005? I was having the same problem. However when you rebuild the
entire web site it then compiles everything and you can pick up the
properties.

Hope this helps,

Corey
 
N

Nathan Sokalski

I do use Rebuild in VS.NET 2005, but I still receive the error. I have a
feeling that it is possible that my problem might be in that there is an
error somewhere else that is preventing the controls from compiling, since
it seems like this happens sometimes and not others. However, I am not sure
how to find where the other error is (if my suspicion is true) since it does
not list it in the compilation errors because it does not get to that point
in the compilation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top