Code behind variable in html control attribute problem
I have a boolean in my code behind that I want to control the visibility of a control but I get a databinding error. Not sure if my syntax is correct.
I've simplified what I am doing below. I have no problem accessing public and protected variables in html via <%=whatever%> but when I try to apply to a control attribute it isn't working.
VB Code:
Protected myBoolean as boolean=false
<html>
<Component:myComponent Visible="<%# myBoolean%>"/>
</html>
Re: Code behind variable in html control attribute problem
I'll take a shot at this. I think the reason might be that the control wants a string, not a boolean value.
Try doing this:
Code:
Protected myBoolean as String = "false"
<html>
<Component:myComponent Visible="<%= myBoolean%>"/>
</html>
Let me know!
Re: Code behind variable in html control attribute problem
Tried that one to
Error is:
<%=myBoolean%> is not a valid value for Boolean
Re: Code behind variable in html control attribute problem
Me.MyControl.Visible = myBoolean
Re: Code behind variable in html control attribute problem
Where are talking the HTML side of things
Re: Code behind variable in html control attribute problem
I would do it in the codebehind, but you could try this:
<html>
<Component:myComponent Visible="<%= myBoolean.toString %>"/>
</html>
No idea if this works, never do it this way.
Re: Code behind variable in html control attribute problem
Quote:
Originally Posted by gtilles
Where are talking the HTML side of things
What I've shown is the same thing, only it's the proper way to facilitate separation of UI and UI logic. :)
Re: Code behind variable in html control attribute problem
Thanks but....my question was doing it on the HTMl side not how to do it on the code behind. I am already aware of how to do it on the code-behind.....but in this case, proper coding or not...I want it on the HTML.
This is the question. not looking for alternate answers. ;)