views:

243

answers:

2

Why isn't this working?

<ajaxToolkit:TabPanel Enabled='<%# User.IsInRole("admin") %>'...

While this works:

<asp:TextBox Enabled='<%# User.IsInRole("admin") %>'...
A: 

Is the first example within a binding context (bound control)? Perhaps you want to use the output directive instead of the binding directive?

<ajaxToolkit:TabPanel Enabled='<%= User.IsInRole("admin") %>'

EDIT: My bad. <%= %> translates into Response.Write, which is not what you want -- too used to ASP.NET MVC, I guess. The best thing is to make it runat="server", give it an ID and set the value in your code-behind.

<ajaxToolkit:TabPanel runat="server" ID="myTabs" ... />


protected void Page_Load( object sender, EventArgs e )
{
    myTabs.Enabled = User.IsInRole("admin");
    ...
}
tvanfosson
Hmm...That seems correct, missed that. However, now it raises the following,Parser Error Message: Cannot create an object of type 'System.Boolean' from its string representation '<%= User.IsInRole("admin") %>' for the 'Enabled' property.
henrico
Yeah, <%= %> only works on client-side code. MS assumes that if you are using a server-side control you will be data binding or setting properties in code-behind.
BJ Safdie
A: 

Ok, thats not a bugg then.

henrico