Kind of an interesting problem. But, as the error message says, the string <%= WebApplication1.SiteHelper.IsUserInRole("Admin") %> cannot be converted to logical.
Unfortunately, I cannot explain why the expression is not evaluated, but is instead treated as a string.
The reason your expression <%# %> works as expected is because it is interpreted differently. When the page is compiled into a class, then the compiler creates an event handler similar to this:
public void __DataBindingButton2(object sender, EventArgs e) { Button button = (Button) sender; Page bindingContainer = (Page) button.BindingContainer; button.Visible = HttpContext.Current.User.IsInRole("admin"); }
and it hooks this method before the Control.Databinding event on your control. As you can see, <%# %> this time is correctly processed as server code, and not just a random string.
So, I think the solution is to use data binding or go to code code, as Andreas Knudsen suggests.
Tom Jelen Dec 15 '08 at 23:43 2008-12-15 23:43
source share