How to pass the current user into a web control declaratively

I am creating a control and have to pass it to the current login user as a parameter (declaratively)

I tried this but didn't work (I got "<% = User.Identity.Name%>" as value):

<cc1:MyControl id="myid" runat="server" User="<%= User.Identity.Name %>" />

      

Is there a way to do this?

+1


source to share


5 answers


Why would you transfer at all? The user control can directly access the User.Identity.Name property.



+2


source


Inside this control, you will have access to this.Page.User, so one way. Another is the use of HttpContext.Current.User.



+1


source


You can do it in codebehind:

myid.User = User.Identity.Name

      

+1


source


Try using:

User="<%= User.Identity.Name %>"

      

% = for output

% # for data binding.

0


source


Try changing the double quotes in the User attribute to single quotes. I've seen this work in the past ...

0


source







All Articles