Here is a simplified example of what I am trying to achieve;
<asp:CheckBox runat="server" Checked="<%# this.isChecked %>" id="myCheckBox" />
Then in my code behind;
public partial class _Default : System.Web.UI.Page
{
bool _isChecked = true;
public string isChecked
{
get
{
return _isChecked.ToString();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
I am aware that, in this case, I can simply use myCheckBox.Checked = true, but I'm just using this example for illustration purposes. The real control is a custom one, but I'm not having any luck getting this approach to work. It just seems to ignore the value I'm supplying.
Is it valid to use <%# this.isChecked %> in this manner?
EDIT:
Sorry, I wrote this in a hurry and realise that it's not really clear that I intended "checkbox" to just be an example. I'm just trying to get a server-side bool into any particular attribute of the ASP control, not necessarily the "checked" attribute of the checkbox control.
EDIT 2: Updated my example to use string property rather than boolean field, but it is reporting the following error in my ASPX file now;
Cannot convert type 'string' to 'bool'