Hiral Bavisi
Hiral Bavisi

Reputation: 91

Button cant working properly

I am working on visual studio 2010 with SQL Server Management studio.

I have made a button for deleting selected rows from the table.

<asp:Button ID="btnDeleteSelectedMessages" runat="server" 
    Text="Verwijderen" Enabled="false" 
    OnClick="btnDeleteSelectedMessages_Click" />

It works perfectly for the first time when I run the page first time.

then after the button can't be clicked second time.

the code on button click event is like this.

protected void btnDeleteSelectedMessages_Click(object sender, EventArgs e)
{
    if (currentGridView == null)
        setCurrentGridView();

    //controleer voor elke rij welke checkbox is geselecteerd
    foreach (GridViewRow row in currentGridView.Rows)
    {
        var cb = (HtmlInputCheckBox)row.FindControl("chkPaid");
        Guid messageID = (Guid)currentGridView.DataKeys[row.DataItemIndex].Value;

        //als de checkbox is geselecteerd het bericht verwijderen
        if (cb != null && cb.Checked)
        {
            if (currentGridView.ID.Equals("Messages"))
                b.BussinesMessageReceiver.DeleteMessageReceiver(messageID, MessageBoxPerson);
            else if (currentGridView.ID.Equals("MessagesSent"))
                b.BussinesMessage.DeleteMessageSender(messageID);
            else //MessagesDeleted
                b.BussinesMessage.DeleteMessage(messageID, (Page.Server.MapPath("~/Upload/") + messageID));
            continue;
        }
    }
    btnDeleteSelectedMessages.Enabled = false;
    selectLocation.Visible = false;
    clearSelectedMessageSession();

    //Update the GridView
    BindGridView();
}

Can any one help me?

Upvotes: 0

Views: 119

Answers (4)

Kishore Kumar
Kishore Kumar

Reputation: 12864

You should enable PostBack for your button..

Upvotes: 0

Hans Kesting
Hans Kesting

Reputation: 39265

With this code:

btnDeleteSelectedMessages.Enabled = false;

you DISable the button. Do you maybe enable that button in the Page_Load? The Button_Click handler fires after the Load, so you end up with a disabled button.

So you need to remove that line (why did you put it in there?)

Upvotes: 3

Anand
Anand

Reputation: 1450

Try with this code

btnDeleteSelectedMessages.Enabled = false; 

Upvotes: 0

vikrantx
vikrantx

Reputation: 603

Button must to Enable (Enable="true") to work,

<asp:Button ID="btnDeleteSelectedMessages" runat="server" Text= "Verwijderen" Enabled="true" OnClick="btnDeleteSelectedMessages_Click" />

Upvotes: 1

Related Questions