I'm creating a control and need to pass it the current logon 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 it?
From stackoverflow
-
Try using:
User="<%= User.Identity.Name %>"%= is for output
%# is for databinding.
Juan Manuel : Sorry, I fixed it (I copied and pasted the second thing I tried). I did actaully tried first with "=" -
Try changing the double quotes in the User attribute to single quotes. I've seen that work in the past...
-
Inside that control, you will have access to this.Page.User, so that's one way. Another is to use HttpContext.Current.User.
-
Why do you need to pass it at all?. The user control can access the User.Identity.Name property directly.
Juan Manuel : hmm... I should have thought about it a little more... I think you are right... -
You can do this in the codebehind:
myid.User = User.Identity.Name
0 comments:
Post a Comment