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

  • Thread starter Thread starter Author
  • Start date Start date
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.
 
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)
 
Back
Top