I am facing an issue with a Javascript popup box that should appear when a user clicks on an action button within a gridview. Currently, the popup only opens after the code in the sub has executed entirely, leading to a variable not getting assigned values in time. How can I ensure that the popup opens before the end of the sub and allows the user to input values for the DelUserConfirm variable? Here is the code snippet:
Sub Gridview_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
Dim currentcommand As String = e.CommandName
' more variables...
If e.CommandName = "DelUser" Then
Dim DelUserConfirm As String = Request.Form("confirm_value")
If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
Page.ClientScript.RegisterStartupScript(GetType(action), _
"alert", "Confirm()", True)
End If
If DelUserConfirm = "Yes" Then
' deletion logic...
End If
Exit Sub
End If
If e.CommandName = "EditUser" Then
' edit logic...
End If
End Sub
Here's the webform code...
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="UserAdmin.aspx.vb" Inherits="_3rd_party_data_reporting_tool.UserAdmin" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<script type = "text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Are you sure you want to Delete this user?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
<body>
<form id="UserAdmin" runat="server">
<!-- Page content... -->
</form>
</body>
</html>