Pieczarr
Pieczarr

Reputation: 358

Dynamically added button omits confirm

I'm developing a website for users where I add controls dynamically.

The problem is that after a confirmBox appears it doesn't matter what I click (Ok/Cancel) it still deletes my objects.

This is how I add them from codeBehind:

aPanel.RegisterAction("DeleteStuff", "Delete object", 
                            true, btnDeleteClick, null);

where aPanel is ActionPanelDx

right after this comes:

if (actionPanel["DeleteStuff"] != null)
    actionPanel["DeleteStuff"].ClientSideEvents.ItemClick = 
    "function(s,e){return confirm('Are you sure you want to delete?')}";

protected void btnDelete_Click(object sender, MenuItemEventArgs e)
{
    //Im using self written classes for handlig SQL logic it looks like this: 
    MySQLCommand commad = new MySQLCommand("delete_object");//procedure
    commad.MyParam.AddWithValue("@ob_id", ObjectID);
    commad.myExecuteNonQuery();
}

Am I using the JS function in a wrong?

Upvotes: 0

Views: 54

Answers (1)

Almis
Almis

Reputation: 3809

Now what your code does it to delete your object whenever a button (doesn't matter which) is clicked. What you need to do is something like that:

protected void btnDelete_Click(object sender, MenuItemEventArgs e)
{
    if (e.item.name === "Yes")
    {
        MySQLCommand commad = new MySQLCommand("delete_object");//procedure
        commad.MyParam.AddWithValue("@ob_id", ObjectID);
        commad.myExecuteNonQuery();
    }
}

instead of e.item.name it could be e.item.text or something like that, put a breakpoint or console.log to see what is inside of your e property if you not sure.

Upvotes: 1

Related Questions