travisowens
Centurion
Note: issue resolved, see 2 posts down as I've included my fix for others to find
In pre-ASP.Net days if one wanted to add a popup that made a user confirm a delete action all one had to do was add the following Javascript to the item...
onclick="Javascript:return confirm('You are sure you want to permenatly delete this record, is this ok?')"
But it seems when I paste this into ASP.Net I get a very generic error
Compiler Error Message: CS1026: ) expected
Even though THERE IS NOT A PROBLEM WITH MY ()s anywhere, I've even had a 2nd developer double check my code. A quick google search reveals at least 2 other people have had this same problem but no formal resolution/explanation was given.
I also cannot use a btnDelete.Parameters.Add() to add an Javascript OnClick event in my Page_Load because this isn't a normal form button, the button is part of a DataGrid column using the Edit Template. I even tried adding the OnClick parameter to the ItemDataBound event like so (because it's the only place that I know of to access datagrid template buttons on a per button level)
private void dgResults_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.FindControl("btnDelete").Attributes.Add("onclick","javascript:if(confirm('Are you sure?')== false) return false;");
}
But this didn't work either
So does anybody know how to add a "Are you sure" Javascript dialog to an ImageButton being generated by a DataGrid's template column? I know I could hack up a work-around using a new webform but I don't want to go that extreme.
I've already tried these random things, which didn't not work:
1. Changing the quotes from ' to " (and vice versa)
2. Removing the () from the javascript
3. Rearranging the OnClick="" more ways than you can imagine
In pre-ASP.Net days if one wanted to add a popup that made a user confirm a delete action all one had to do was add the following Javascript to the item...
onclick="Javascript:return confirm('You are sure you want to permenatly delete this record, is this ok?')"
But it seems when I paste this into ASP.Net I get a very generic error
Compiler Error Message: CS1026: ) expected
Even though THERE IS NOT A PROBLEM WITH MY ()s anywhere, I've even had a 2nd developer double check my code. A quick google search reveals at least 2 other people have had this same problem but no formal resolution/explanation was given.
I also cannot use a btnDelete.Parameters.Add() to add an Javascript OnClick event in my Page_Load because this isn't a normal form button, the button is part of a DataGrid column using the Edit Template. I even tried adding the OnClick parameter to the ItemDataBound event like so (because it's the only place that I know of to access datagrid template buttons on a per button level)
private void dgResults_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.FindControl("btnDelete").Attributes.Add("onclick","javascript:if(confirm('Are you sure?')== false) return false;");
}
But this didn't work either
So does anybody know how to add a "Are you sure" Javascript dialog to an ImageButton being generated by a DataGrid's template column? I know I could hack up a work-around using a new webform but I don't want to go that extreme.
I've already tried these random things, which didn't not work:
1. Changing the quotes from ' to " (and vice versa)
2. Removing the () from the javascript
3. Rearranging the OnClick="" more ways than you can imagine
Last edited: