Possible to bind the Enabled property of a button to a method?

A

Author

I am curious about this. Is it possible to bind the Enabled property
to a method in my code behind?

So, suppose I have this method in code-behind (a code skeleton only,
not real code)

protected bool IsCancelOrderButtonEnabled()
{
bool isEnabled = true;

DataTable customerOrder = GetCustomerOrder();

if (customerOrder.Rows[0]["ShipStatus"].ToString().ToLower().Equals
("true"))
{
isEnabled = false;
}

return isEnabled;
}

Now, in the markup, can I do the following?

<asp:Button ID="btnCancelOrder" runat="server" Text="Cancel Order"
Enabled='<%# IsCancelOrderButtonEnabled() %>' />

I tried, it didn't work.
 
B

bruce barker

yes, but you need to call databind() to invoke the binding or make the
button a child of a control that does databinding.


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top