Add attribute from external javascript file

ManicCW

Well-known member
Joined
Jul 21, 2005
Messages
428
Location
Mostar
Programming Experience
Beginner
Hi,
I need to add attribute to button in datagrid. I use this in datagrid ItemDataBound event:

VB.NET:
Dim imgDelete As ImageButton = CType(e.Item.Cells(6).FindControl("imgDelete"), ImageButton)
imgDelete.Attributes.Add("onClick", "ConfirmDelete()")

Now this javascript function is located in external file. Here is function:

VB.NET:
function ConfirmDelete(){
return confirm("Ovom akcijom trajno brisete zapis!\nOK za nastavak.\nCancel za ponistavanje akcije.");
}

Now when confirm box is raised and I click Cancel postback occurs!?
Postback does not occur when I use javascript function in page itself like:

VB.NET:
imgDelete.Attributes.Add("onClick", "return confirm('Ovom akcijom trajno brisete zapis!\nOK za nastavak.\nCancel za ponistavanje akcije.');")

What is the problem here???
 
In the ItemDataBound Event, change that to:
VB.NET:
imgDelete.Attributes.Add("onClick", "return ConfirmDelete()")

and make sure ConfirmDelete() returns false. Returning false will stop the postback from happening and it has to be returned from the OnClick of the button
 
Back
Top