It can frequently be quite useful to ask the user to confirm their submit request in an ASP.Net page. There are a lot of code samples out there that "emit" javascript in the server-side function once the postback has been issued. This can be appropriate if you need to do parameter validation or any background processing before asking for confirmation. However, for situations where you just want to make sure the button was not clicked by accident, this works quite well:
<asp:Button ID="bnTruncateDB" runat="server" OnClick="bnTruncateDB_Click"
Text="Truncate The Database"
OnClientClick="return confirm('Are you sure you want to remove all DB entries?');" />
The generated HTML code calls Javascript confirm(...) function when the client-side onclick event is raised. The postback will only be processed if the confirm(...) call returns true (user clicks 'Yes').
Cheers!
Recent comments