Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > UserControl Problem

Reply
Thread Tools

UserControl Problem

 
 
=?Utf-8?B?VGltOjouLg==?=
Guest
Posts: n/a
 
      01-21-2005
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

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      01-21-2005
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:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?VGltOjouLg==?=
Guest
Posts: n/a
 
      01-22-2005
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:(E-Mail Removed)...
> > 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
> >

>
>
>

 
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
Postback problem with usercontrol in usercontrol Mark van Bree ASP .Net Web Controls 1 05-30-2006 08:27 PM
accessing usercontrol from another usercontrol Phl ASP .Net 2 11-18-2004 07:33 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments