referencing a user control: ASP.NET 2.0

Discussion in 'ASP .Net' started by Jimi, Mar 26, 2006.

  1. Jimi

    Jimi Guest

    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
    Jimi, Mar 26, 2006
    #1
    1. Advertising

  2. Jimi

    Guest

    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
    , Mar 26, 2006
    #2
    1. Advertising

  3. 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/reference/infrastructure/wap/

    Karl



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



    "Jimi" <> wrote in message
    news:...
    > 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
    >
    Karl Seguin [MVP], Mar 26, 2006
    #3
  4. Jimi

    Jimi Guest

    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:...
    > 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/reference/infrastructure/wap/
    >
    > Karl
    >
    >
    >
    > --
    > http://www.openmymind.net/
    >
    >
    >
    > "Jimi" <> wrote in message
    > news:...
    >> 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
    >>

    >
    >
    Jimi, Mar 26, 2006
    #4
  5. I said "Reference" Not "Register" :)

    Karl

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



    "Jimi" <> wrote in message
    news:...
    > 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:...
    >> 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/reference/infrastructure/wap/
    >>
    >> Karl
    >>
    >>
    >>
    >> --
    >> http://www.openmymind.net/
    >>
    >>
    >>
    >> "Jimi" <> wrote in message
    >> news:...
    >>> 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
    >>>

    >>
    >>

    >
    >
    Karl Seguin [MVP], Mar 27, 2006
    #5
  6. Jimi

    Jimi Guest

    Thanks for your help Kal :)

    Cheers
    Mark
    "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
    net> wrote in message news:%...
    >I said "Reference" Not "Register" :)
    >
    > Karl
    >
    > --
    > http://www.openmymind.net/
    >
    >
    >
    > "Jimi" <> wrote in message
    > news:...
    >> 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:...
    >>> 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/reference/infrastructure/wap/
    >>>
    >>> Karl
    >>>
    >>>
    >>>
    >>> --
    >>> http://www.openmymind.net/
    >>>
    >>>
    >>>
    >>> "Jimi" <> wrote in message
    >>> news:...
    >>>> 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
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Jimi, Mar 27, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. martin
    Replies:
    1
    Views:
    3,081
    abhi17sep
    Mar 29, 2008
  2. Norton
    Replies:
    2
    Views:
    5,060
    Norton
    Jul 26, 2004
  3. =?Utf-8?B?Q2hyaXMgRGF2b2xp?=

    Referencing a User Control from ASPX page

    =?Utf-8?B?Q2hyaXMgRGF2b2xp?=, Aug 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    355
    =?Utf-8?B?Q2hyaXMgRGF2b2xp?=
    Aug 8, 2006
  4. James Page

    User control referencing

    James Page, Sep 19, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    338
    James Page
    Sep 20, 2008
  5. Jay Esguerra
    Replies:
    0
    Views:
    145
    Jay Esguerra
    Oct 13, 2003
Loading...

Share This Page