473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why doesn't this work if in a UserControl?

This code comes directly from Microsoft's site:

Imports System.Security

Add the following code to the Page_Load event procedure:

Dim authUserName As String
Dim aspUserName As String
authUserName = User.Identity.Name
aspUserName = Principal.WindowsIdentity.GetCurrent.Name

If I put the code in a webform (.aspx file) it works. But, if I try to
put it in a user control, I get the little blue squigly line under the
word User. (right before .Identity.Name). Why is that?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
2 997
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/
"Jason ." <jr****@yahoo.com> wrote in message
news:OV****************@TK2MSFTNGP11.phx.gbl...
This code comes directly from Microsoft's site:

Imports System.Security

Add the following code to the Page_Load event procedure:

Dim authUserName As String
Dim aspUserName As String
authUserName = User.Identity.Name
aspUserName = Principal.WindowsIdentity.GetCurrent.Name

If I put the code in a webform (.aspx file) it works. But, if I try to
put it in a user control, I get the little blue squigly line under the
word User. (right before .Identity.Name). Why is that?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2
Hello Karl Seguin,

The other way to go would be to reference:

HttpContext.Current.User.Identity.Name

--
Matt Berther
http://www.mattberther.com
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

"Jason ." <jr****@yahoo.com> wrote in message
news:OV****************@TK2MSFTNGP11.phx.gbl...
This code comes directly from Microsoft's site:

Imports System.Security

Add the following code to the Page_Load event procedure:

Dim authUserName As String
Dim aspUserName As String
authUserName = User.Identity.Name
aspUserName = Principal.WindowsIdentity.GetCurrent.Name
If I put the code in a webform (.aspx file) it works. But, if I try
to put it in a user control, I get the little blue squigly line under
the word User. (right before .Identity.Name). Why is that?

*** Sent via Developersdex http://www.developersdex.com *** Don't
just participate in USENET...get rewarded for it!

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Henke | last post by:
I added a project to my solution that contains a user control. Now I 'd like to add the user control from that project to a form in my solution. The problem is that the control doesn't gets added...
7
by: Peter Proost | last post by:
Hi group, Here at work they've got an activeX control which is used on a usercontrol, and this usercontrol is one of the standard controls in the framework, so this user controls get's used a...
9
by: Henke | last post by:
I added a project to my solution that contains a user control. Now I 'd like to add the user control from that project to a form in my solution. The problem is that the control doesn't gets added...
1
by: dusanv | last post by:
Hi, I have a class (say O1) that overrides System::Windows::Forms::UserControl and then another one that overrides O1 (call it O2). O2 used to work with the Designer as it was inheriting...
6
by: Johnny Jörgensen | last post by:
I've got a usercontrol derived from a normal ComboBox that contains some special formatting code. On my main form I've got a lot of my custom comboboxes. I discovered a bug in the derived...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.