Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > referencing a user control: ASP.NET 2.0

Reply
Thread Tools

referencing a user control: ASP.NET 2.0

 
 
Jimi
Guest
Posts: n/a
 
      03-26-2006
Hi, I have a user control on my page and all I would like to do is call one
of its public methods.

in 1.1 I would just go...

((MyUserControlType)(NamedInstanceOfControl)).Publ icMethod();

e.g. as a trivial example

((string)(_myStringInstance)).ToLower();

However in 2.0 I cannot seem to get a reference to MyUserControlType as it
does not appear in the intellisense. Even latebinding does not work..

Any help appreciated
Cheers
Mark


 
Reply With Quote
 
 
 
 
brian.f.oneil@gmail.com
Guest
Posts: n/a
 
      03-26-2006
You should not need to cast the type of that control.
Your syntax should be something like : MyString =
MyControl1.Property1.ToString().

That is the start. Then the issue of not seeing it in Intellisense is
common. Try switching to design mode and double-clicking the control.
That will put an "OnLoad" event handler for the control in your code
which you can go back and erase. I used to have your same problem in
1.1, and solved it always by adding an instance variable in the code as
in :

Protected MyControlType MyControl1;

Look in the markup for your page and make sure you have a Tag
Registration for the control at the top of the page.

HTH,
Brian

 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      03-26-2006
Use the @Referencesdirective on the page and point it to the ascx, ala:

<%@ Reference Control="controls/blah.ascx" %>

There's also a beta Web Application Project that mimics the 1.x model for
2.0:
http://msdn.microsoft.com/asp.net/re...structure/wap/

Karl



--
http://www.openmymind.net/



"Jimi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, I have a user control on my page and all I would like to do is call
> one of its public methods.
>
> in 1.1 I would just go...
>
> ((MyUserControlType)(NamedInstanceOfControl)).Publ icMethod();
>
> e.g. as a trivial example
>
> ((string)(_myStringInstance)).ToLower();
>
> However in 2.0 I cannot seem to get a reference to MyUserControlType as it
> does not appear in the intellisense. Even latebinding does not work..
>
> Any help appreciated
> Cheers
> Mark
>



 
Reply With Quote
 
Jimi
Guest
Posts: n/a
 
      03-26-2006
Hi, yes I do actually already have this

<%@ Register Src="UserControls/UploadDrivers.ascx" TagName="UploadDrivers"
TagPrefix="uc2" %>

I think the difference is between 1.1 where each page was a class and in 2.0
where a page is a partial class.

All I want to be able to do is (Say I have a usercontrol called
UploadDrivers1 on my page) is do the following in code behind:

((UploadDrivers)(UploadDrivers1)).PublicMethod();

However in the codebehind page I cannot get a reference to the UploadDrivers
class.
e.g. If I type in UploadD and then wait for intellisense to pick up that
there is a class called UploadDrivers nothing happens. It's like VS cannot
figure out that there is in fact a class called UploadDrivers (hence my
reasoning that the partial classes have something to do with the problem).

I checked that my UploadDrivers was not under some obscure namespace but it
is not..

Thanks for you help
Cheers
Mark


"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:(E-Mail Removed)...
> Use the @Referencesdirective on the page and point it to the ascx, ala:
>
> <%@ Reference Control="controls/blah.ascx" %>
>
> There's also a beta Web Application Project that mimics the 1.x model for
> 2.0:
> http://msdn.microsoft.com/asp.net/re...structure/wap/
>
> Karl
>
>
>
> --
> http://www.openmymind.net/
>
>
>
> "Jimi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi, I have a user control on my page and all I would like to do is call
>> one of its public methods.
>>
>> in 1.1 I would just go...
>>
>> ((MyUserControlType)(NamedInstanceOfControl)).Publ icMethod();
>>
>> e.g. as a trivial example
>>
>> ((string)(_myStringInstance)).ToLower();
>>
>> However in 2.0 I cannot seem to get a reference to MyUserControlType as
>> it does not appear in the intellisense. Even latebinding does not work..
>>
>> Any help appreciated
>> Cheers
>> Mark
>>

>
>



 
Reply With Quote
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      03-27-2006
I said "Reference" Not "Register"

Karl

--
http://www.openmymind.net/



"Jimi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, yes I do actually already have this
>
> <%@ Register Src="UserControls/UploadDrivers.ascx" TagName="UploadDrivers"
> TagPrefix="uc2" %>
>
> I think the difference is between 1.1 where each page was a class and in
> 2.0 where a page is a partial class.
>
> All I want to be able to do is (Say I have a usercontrol called
> UploadDrivers1 on my page) is do the following in code behind:
>
> ((UploadDrivers)(UploadDrivers1)).PublicMethod();
>
> However in the codebehind page I cannot get a reference to the
> UploadDrivers class.
> e.g. If I type in UploadD and then wait for intellisense to pick up that
> there is a class called UploadDrivers nothing happens. It's like VS cannot
> figure out that there is in fact a class called UploadDrivers (hence my
> reasoning that the partial classes have something to do with the problem).
>
> I checked that my UploadDrivers was not under some obscure namespace but
> it is not..
>
> Thanks for you help
> Cheers
> Mark
>
>
> "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
> net> wrote in message news:(E-Mail Removed)...
>> Use the @Referencesdirective on the page and point it to the ascx, ala:
>>
>> <%@ Reference Control="controls/blah.ascx" %>
>>
>> There's also a beta Web Application Project that mimics the 1.x model for
>> 2.0:
>> http://msdn.microsoft.com/asp.net/re...structure/wap/
>>
>> Karl
>>
>>
>>
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "Jimi" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi, I have a user control on my page and all I would like to do is call
>>> one of its public methods.
>>>
>>> in 1.1 I would just go...
>>>
>>> ((MyUserControlType)(NamedInstanceOfControl)).Publ icMethod();
>>>
>>> e.g. as a trivial example
>>>
>>> ((string)(_myStringInstance)).ToLower();
>>>
>>> However in 2.0 I cannot seem to get a reference to MyUserControlType as
>>> it does not appear in the intellisense. Even latebinding does not work..
>>>
>>> Any help appreciated
>>> Cheers
>>> Mark
>>>

>>
>>

>
>



 
Reply With Quote
 
Jimi
Guest
Posts: n/a
 
      03-27-2006
Thanks for your help Kal

Cheers
Mark
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%(E-Mail Removed)...
>I said "Reference" Not "Register"
>
> Karl
>
> --
> http://www.openmymind.net/
>
>
>
> "Jimi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi, yes I do actually already have this
>>
>> <%@ Register Src="UserControls/UploadDrivers.ascx"
>> TagName="UploadDrivers" TagPrefix="uc2" %>
>>
>> I think the difference is between 1.1 where each page was a class and in
>> 2.0 where a page is a partial class.
>>
>> All I want to be able to do is (Say I have a usercontrol called
>> UploadDrivers1 on my page) is do the following in code behind:
>>
>> ((UploadDrivers)(UploadDrivers1)).PublicMethod();
>>
>> However in the codebehind page I cannot get a reference to the
>> UploadDrivers class.
>> e.g. If I type in UploadD and then wait for intellisense to pick up that
>> there is a class called UploadDrivers nothing happens. It's like VS
>> cannot figure out that there is in fact a class called UploadDrivers
>> (hence my reasoning that the partial classes have something to do with
>> the problem).
>>
>> I checked that my UploadDrivers was not under some obscure namespace but
>> it is not..
>>
>> Thanks for you help
>> Cheers
>> Mark
>>
>>
>> "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
>> net> wrote in message news:(E-Mail Removed)...
>>> Use the @Referencesdirective on the page and point it to the ascx, ala:
>>>
>>> <%@ Reference Control="controls/blah.ascx" %>
>>>
>>> There's also a beta Web Application Project that mimics the 1.x model
>>> for 2.0:
>>> http://msdn.microsoft.com/asp.net/re...structure/wap/
>>>
>>> Karl
>>>
>>>
>>>
>>> --
>>> http://www.openmymind.net/
>>>
>>>
>>>
>>> "Jimi" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> Hi, I have a user control on my page and all I would like to do is call
>>>> one of its public methods.
>>>>
>>>> in 1.1 I would just go...
>>>>
>>>> ((MyUserControlType)(NamedInstanceOfControl)).Publ icMethod();
>>>>
>>>> e.g. as a trivial example
>>>>
>>>> ((string)(_myStringInstance)).ToLower();
>>>>
>>>> However in 2.0 I cannot seem to get a reference to MyUserControlType as
>>>> it does not appear in the intellisense. Even latebinding does not
>>>> work..
>>>>
>>>> Any help appreciated
>>>> Cheers
>>>> Mark
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Re: Referencing user control variables from page martin ASP .Net 1 03-29-2008 11:41 AM
Referencing User controls from content pages using ContentPlaceHolders jgdean14 ASP .Net 0 11-05-2007 11:25 PM
Referencing a User Control from ASPX page =?Utf-8?B?Q2hyaXMgRGF2b2xp?= ASP .Net 0 08-08-2006 09:11 PM
Referencing a User Control in web form code (C#) Norton ASP .Net 2 07-26-2004 05:10 PM
Referencing controls on user controls Jim Corey ASP .Net 1 01-26-2004 07:47 PM



Advertisments