开发者

bind checkbox enable property to code behind method

开发者 https://www.devze.com 2023-03-10 23:18 出处:网络
I have a check box ona page. I want to set it\'s enable property from a codebehind method. I have done thisEnabled= \'<%#IsSMSEnabled()%>\' />

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 bo开发者_如何转开发x is alwyas enabled no matter what is returned by IsSMSEnabled()%


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();
}


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

<%= sSMSEnabled() %>


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消