Hi,

I'm creating a page that has an ASP button that should delete a row of data from an SQL database. I want a javascript confirm window to appear to make sure the user really wants to delete the information. I can set the button's OnClientClick property to "javascript:confirm('Are you sure you want to delete this item?')", but the server-side event, Button_Command, still occurs regardless of whether yes or no is chosen in the confirm window. How can I fix this?

-James

I tried setting the onClientClick property to if (confirm('Are you sure you want to delete this item?')){form1.submit;} but the result is still the same.

I tried setting the onClientClick property to if (confirm('Are you sure you want to delete this item?')){form1.submit;} but the result is still the same.

for the onClientClick, if confirm returns a bool try using this for the code

onclick="return confirm('Are you sure you want to delete this item?')"

you can also put that in the onsubmit(?) event of a form. basicaly if a funtion returns false after an even it will no submit the form , otherwise if it is true the form does get submit. same goes for an onclick in a button. if it returns false the action which should happen after the click, will not happen

Thanks, that's just what I needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.