469,954 Members | 1,812 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,954 developers. It's quick & easy.

Compilation of UserControls

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 Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Jan 18 '07 #1
4 951
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.

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:uI**************@TK2MSFTNGP04.phx.gbl...
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 Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Jan 18 '07 #2
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.

"Nathan Sokalski" wrote:
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 Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Jan 20 '07 #3

Nathan Sokalski wrote:
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 Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
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

Jan 20 '07 #4
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.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Corey B" <co***********@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
>
Nathan Sokalski wrote:
>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 Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

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

Jan 21 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Anders K. Jacobsen [DK] | last post: by
3 posts views Thread by YYZ | last post: by
reply views Thread by seigo | last post: by
4 posts views Thread by Nathan Sokalski | last post: by
7 posts views Thread by Nathan Sokalski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.