user228777
user228777

Reputation: 3094

bind checkbox enable property to code behind method

I have a check box on a page. I want to set it's enable property from a codebehind method. I have done this Enabled= '<%#IsSMSEnabled()%>' />

IsSMSEnabled returns true or false depending on some logic.

Check box is alwyas enabled no matter what is returned by IsSMSEnabled()%

Upvotes: 1

Views: 808

Answers (4)

zer0w1dthspace
zer0w1dthspace

Reputation: 1052

try <%= bool.Parse(IsSMSEnabled()) %>

Upvotes: 0

tugberk
tugberk

Reputation: 58454

It depends on where you return the value from.

Try to set a property and assign its value inside code behind.

EDIT

I just heard that your checkbox is not inside a data control. So that would make more sense to directly change the checkbox.Checked value.

Upvotes: 0

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

The <%# expressions are evaluated at DataBind() time and are not evaluated at all if DataBind() is not called. You can call DataBind() in PreRenderComplete

protected void Page_PreRenderComplete(object sender, EventArgs e)
{
    DataBind();
}

Upvotes: 1

CheckRaise
CheckRaise

Reputation: 550

Instead of wrapping your method call in <%# %>, try wrapping it in <%= %>

<%= sSMSEnabled() %>

Upvotes: 0

Related Questions