views:

115

answers:

5

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?

A: 

Try using:

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

%= is for output

%# is for databinding.

FlySwat
Sorry, I fixed it (I copied and pasted the second thing I tried). I did actaully tried first with "="
Juan Manuel
A: 

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

Will
+1  A: 

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

Doug McClean
+2  A: 

Why do you need to pass it at all?. The user control can access the User.Identity.Name property directly.

HectorMac
hmm... I should have thought about it a little more... I think you are right...
Juan Manuel
+1  A: 

You can do this in the codebehind:

myid.User = User.Identity.Name
Josh Hinman