sys_debug
sys_debug

Reputation: 4003

Disable button if boolean variable is true

I've found topics covering disabling buttons to avoid submitting twice (assuming this could be done via javascript), but what i need is to disable button of submit if field "formSubmitted" in the database holds true value. otherwise this means the form has not been submitted and this submit is required. Any idea how to do this?

  <asp:TableCell>
        <asp:Button id="acceptButton" Text="Accept" runat="server" OnClick="Click"/> 
        <asp:Button id="declineButton" Text="Decline" runat="server" OnClick="DeclineRequest"/> 
    </asp:TableCell></asp:TableRow></asp:Table></form></asp:Content>

so yeh the accept and decline buttons are what i want to disable if formsubmiited variable holds true. Thanks again,

Upvotes: 1

Views: 3245

Answers (5)

Carmelo La Monica
Carmelo La Monica

Reputation: 765

if(acceptButton.Enabled.Equals(true))
{
    acceptButton.Enabled = false;
}

Upvotes: 0

petko_stankoski
petko_stankoski

Reputation: 10713

You can also try

acceptButton.Visible = false;

Upvotes: 0

James Johnson
James Johnson

Reputation: 46047

Try something like this:

declineButton.Enabled = booleanVariable == false;

Or

declineButton.Enabled = !booleanVariable;

Upvotes: 1

GHP
GHP

Reputation: 3231

if (formSubmitted)
{
    acceptButton.Enabled = false; 
    declineButton.Enabled = false;
}

Upvotes: 2

Doozer Blake
Doozer Blake

Reputation: 7797

Use the Enabled property.

if( WhateverYouAreTesting == true )
{
     declineButton.Enabled = false;
}

Upvotes: 1

Related Questions