Hi Vincenzo67,
Refer below sample.
HTML
<asp:Button ID="btnConfirm" runat="server" OnClick="OnConfirm"
Text="Raise Confirm" OnClientClick="Confirm()" />
JavaScript
<script type="text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to save data?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
Code
C#
public void OnConfirm(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
switch (confirmValue)
{
case "Yes":
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
break;
case "No":
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
break;
default:
break;
}
}
VB.Net
Protected Sub OnConfirm(sender As Object, e As EventArgs)
Dim confirmValue As String = Request.Form("confirm_value")
Select Case confirmValue
Case "Yes"
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('You clicked YES!')", True)
Case "No"
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('You clicked NO!')", True)
Case Else
End Select
End Sub
Screenshot