UserControl Problem

Discussion in 'ASP .Net' started by =?Utf-8?B?VGltOjouLg==?=, Jan 21, 2005.

  1. Can some one please tell me why I keep getting an error saying user has not
    been declared when I add the following to a class usercontrol.

    User.Identity.Name

    If it is the page class then there is no problem!!!

    EG:

    Inherits System.Web.UI.Page = OK
    Inherits System.Web.UI.UserControl = Doesn't work

    Can you sue the page class in a usercontrol??? How do I solve this???

    Thanks
    =?Utf-8?B?VGltOjouLg==?=, Jan 21, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?VGltOjouLg==?=

    Karl Seguin Guest

    Because user is a property of the Page class. so in the page, when you are
    doing

    User.Identity.Name

    it's really like doing

    me.User.Identity.Name

    and since me is an instance of Page, it inherits the User property.

    A user control inherits from UserControl, instead of Page, and doesn't have
    the property. To access the page's user from the user control do:
    Page.User.Identity.Name ...as you can see while User isn't a property of
    UserControl, Page is...

    Karl


    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Tim::.." <myatix_at_hotmail.com> wrote in message
    news:...
    > Can some one please tell me why I keep getting an error saying user has

    not
    > been declared when I add the following to a class usercontrol.
    >
    > User.Identity.Name
    >
    > If it is the page class then there is no problem!!!
    >
    > EG:
    >
    > Inherits System.Web.UI.Page = OK
    > Inherits System.Web.UI.UserControl = Doesn't work
    >
    > Can you sue the page class in a usercontrol??? How do I solve this???
    >
    > Thanks
    >
    Karl Seguin, Jan 21, 2005
    #2
    1. Advertising

  3. Thanks!

    "Karl Seguin" wrote:

    > Because user is a property of the Page class. so in the page, when you are
    > doing
    >
    > User.Identity.Name
    >
    > it's really like doing
    >
    > me.User.Identity.Name
    >
    > and since me is an instance of Page, it inherits the User property.
    >
    > A user control inherits from UserControl, instead of Page, and doesn't have
    > the property. To access the page's user from the user control do:
    > Page.User.Identity.Name ...as you can see while User isn't a property of
    > UserControl, Page is...
    >
    > Karl
    >
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Tim::.." <myatix_at_hotmail.com> wrote in message
    > news:...
    > > Can some one please tell me why I keep getting an error saying user has

    > not
    > > been declared when I add the following to a class usercontrol.
    > >
    > > User.Identity.Name
    > >
    > > If it is the page class then there is no problem!!!
    > >
    > > EG:
    > >
    > > Inherits System.Web.UI.Page = OK
    > > Inherits System.Web.UI.UserControl = Doesn't work
    > >
    > > Can you sue the page class in a usercontrol??? How do I solve this???
    > >
    > > Thanks
    > >

    >
    >
    >
    =?Utf-8?B?VGltOjouLg==?=, Jan 22, 2005
    #3
    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. huobazi
    Replies:
    1
    Views:
    667
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    399
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,528
  4. Phl
    Replies:
    2
    Views:
    510
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Nov 18, 2004
  5. Mark van Bree

    Postback problem with usercontrol in usercontrol

    Mark van Bree, May 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    155
Loading...

Share This Page