i have a regular asp:button. I am working in .Net 3.5. I’ve tried adding a js confirm to the button with the OnClientClick attribute as well as adding in code-behind and the result is the same. No matter what the user clicks in the confirm pop-up the form will not submit??
BtnDeleteSelected.Attributes.Add(“onclick”, “return confirm(‘Are you sure you want to delete?’);”);
The confirm dialog appears and if i select “OK” it still does not submit.. Any ideas? thanks.
That’s because you should not be returning in all cases. If you view the source of the page and look for the button markup, you are likely to see this…
The __doPostback invocation is inserted automatically by the ASP.NET framework in some cases. Since you return immediately regardless of the result of
confirm, the postback never fires. The ultimate solution would be to not to set the onclick attribute, but instead use an unobtrusive approach. However, if there is pressing reason to control this on the server-side via onclick, you can use a simpleifstatement and only return when they press “Cancel”…