0

I am using the following C# to replace the texts 'Edit, Delete and Select' from the command row on GridViews.

I want to improve this by using a javascript 'confirm' dialogue to make the user double check before deleting a row. How can I do this from the LinkButton object?

private void commandIcons(GridViewRow row)
{
    if (row.Cells[0].Controls.Count == 5)
    {
        // we have a edit delete select control row type, replace text labels with icons
        LinkButton lbedit = (LinkButton)row.Cells[0].Controls[0];
        lbedit.Text = lbedit.Text == "Edit" ? "<img title=\"Edit\" class=\"icon\" src=\"Images/database_edit.png\" />" : lbedit.Text;

        LinkButton lbdelete = (LinkButton)row.Cells[0].Controls[2];
        lbdelete.Text = lbdelete.Text == "Delete" ? "<img title=\"Delete\" class=\"icon\" src=\"Images/delete.png\" />" : lbdelete.Text;

        LinkButton lbselect = (LinkButton)row.Cells[0].Controls[4];
        lbselect.Text = lbselect.Text == "Select" ? "<img title=\"Select\" class=\"icon\" src=\"Images/accept.png\" />" : lbselect.Text;
    }
}

1 Answer 1

1

You can add an "OnClientClick" to an linkbutton asking for confirmation. And performing an C# function afterwards using "OnClick". Hope it helps.

<asp:LinkButton ID="Deletebutton" runat="server" CausesValidation="False" OnClientClick='return confirm("Are you sure you want to remove this?");'  OnClick="DeleteBrand">

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, OnClientClick was exactly the property I was after!
Good to hear, using it in all the aspx pages myself. Glad I could help out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.