referencing a user control: ASP.NET 2.0

  • Thread starter Thread starter Jimi
  • Start date Start date
J

Jimi

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)).PublicMethod();

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
 
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
 
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:[email protected]...
 
I said "Reference" Not "Register" :)

Karl

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



Jimi said:
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:[email protected]...
 

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

Back
Top