UserControl Problem

G

Guest

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
 
K

Karl Seguin

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
 
G

Guest

Thanks!

Karl Seguin said:
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
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top