Sometimes, we need to add a Javascript confirmation attribute to a button’s click event. When the button is clicked, this will give them an extra pop-up box that says something like, “Are you SURE you want to submit this form?”.
This sample shows how to do this, inside the Page_Load event, showing how to add the ‘onclick’ event as an attribute, to the button which submits the form.
<html>
<head>
<meta name="GENERATOR" Content="ASP Express 2.2">
<title>Confirmation Before Form Submission</title>
<script language="VB" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Button1.Attributes("OnClick") = "return confirm(''Would you like to submit this form?'');"
End Sub
Sub doit(Source as Object, E as EventArgs)
label1.text="The Name you entered is " & txtFirst.text & " " & txtLast.text
End Sub
</script>
</head>
<body>
<Form id="form1" runat="server">
First Name: <asp:TextBox id="txtFirst" runat="server" /><br>
Last Name: <asp:TextBox id="txtLast" runat="server" />
<asp:Button id="Button1" Text="Submit" onclick="doit" runat="server" />
</Form>
<asp:Label ID="label1" runat="server" />
</body>
</html>