PC Review


Reply
Thread Tools Rate Thread

Compilation of UserControls

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      18th Jan 2007
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
(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Gaurav Vaish \(MasterGaurav\)
Guest
Posts: n/a
 
      18th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>



 
Reply With Quote
 
=?Utf-8?B?TmF0aGFuaWVsIEdyZWVuZQ==?=
Guest
Posts: n/a
 
      20th Jan 2007
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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
>
>

 
Reply With Quote
 
Corey B
Guest
Posts: n/a
 
      20th Jan 2007

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
> (E-Mail Removed)
> 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

 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      21st Jan 2007
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
(E-Mail Removed)
http://www.nathansokalski.com/

"Corey B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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
>> (E-Mail Removed)
>> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation of UserControls Nathan Sokalski Microsoft VB .NET 4 21st Jan 2007 06:24 AM
Compilation of UserControls Nathan Sokalski Microsoft ASP .NET 5 21st Jan 2007 06:24 AM
V1.1 compilation model in V2.0 - Loading of UserControls across VDirs Anders Borum Microsoft ASP .NET 1 28th Nov 2005 11:08 PM
Adding usercontrols to other usercontrols =?Utf-8?B?RW1tYQ==?= Microsoft C# .NET 2 27th Oct 2004 03:07 PM
UserControls in UserControls? Phill. W Microsoft VB .NET 0 10th May 2004 03:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:08 PM.