簡體   English   中英

JavaScript確認彈出框打開太晚

[英]Javascript confirm popup box opening too late

我有一個確認動作Javascript彈出框,當用戶單擊gridview中的動作按鈕時,該彈出框應該打開。 我的問題是,直到執行完整個子代碼后,彈出框才會打開,並且需要賦值的變量直到為時已晚才獲取值。 我如何才能打開彈出窗口並允許用戶在子結束之前填充DelUserConfirm變量? 先謝謝您的幫助! 我的代碼如下:

子Gridview_RowCommand(ByVal發送者作為對象,ByVal e作為GridViewCommandEventArgs)

    Dim currentcommand As String = e.CommandName
    Dim index As Integer = Convert.ToInt32(e.CommandArgument)
    Dim cell As GridViewRow = grdUsers.Rows(index)
    Dim currUserID As String = grdUsers.Rows(index).Cells(0).Text

    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

            cmd.Connection = conn
            conn.Open()
            cmd.CommandText = "DELETE FROM USERS WHERE USER_NAME = '" + currUserID + "'"
            cmd.ExecuteNonQuery()
            conn.Close()
            dtUsers.Rows(index).Delete()
            grdUsers.DataSource = dtUsers
            grdUsers.DataBind()

        End If

        Exit Sub

    End If

    If e.CommandName = "EditUser" Then

        Session("EditUserPerms") = dtUsers(index)
        Session("UserPerms") = dtUserPerms
        Response.Redirect("AddEditUser.aspx")

    End If

End Sub

正在添加網絡表單代碼...

<%@ 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">
<asp:Image ID="imgTRLogo" runat="server" Height="120px" ImageUrl="~/TR_Logo.bmp" Width="120px" style="z-index: 1; left: 5px; top: 5px; position: absolute" />
<asp:Label ID="lblTitle1" runat="server" Text="CA - Global Product Operations" Font-Bold="True" Font-Names="Arial Black" Font-Size="XX-Large" style="z-index: 1; left: 170px; top: 20px; position: absolute"></asp:Label>
<asp:Label ID="lblTitle2" runat="server" Text="Productivity Tools" Font-Bold="True" Font-Names="Arial Black" Font-Size="XX-Large" style="z-index: 1; left: 282px; top: 60px; position: absolute"></asp:Label>
<asp:Label ID="lblTitle3" runat="server" Text="User Administration Panel" Font-Bold="True" Font-Names="Arial Black" Font-Size="Large" style="z-index: 1; left: 312px; top: 135px; position: absolute"></asp:Label>
<asp:GridView ID="grdUsers" runat="server" Font-Names="Arial" autogeneratecolumns="false" style="z-index: 1; left: 28px; top: 184px; position: absolute; height: 144px; width: 731px" OnRowCommand="Gridview_RowCommand" >
<Columns>
<asp:BoundField DataField="USER_NAME" HeaderText="User ID"/>
<asp:BoundField DataField="PW" HeaderText="Password"/>
<asp:BoundField DataField="FIRST_NAME" HeaderText="First Name"/>
<asp:BoundField DataField="LAST_NAME" HeaderText="Last Name"/>
<asp:BoundField DataField="EMAIL" HeaderText="E-mail Address"/>
<asp:BoundField DataField="SAFE_ID" HeaderText="SAFE ID"/>
<asp:BoundField DataField="THIRDPTYRPT" HeaderText="3rd Party Report"/>
<asp:BoundField DataField="EDTK" HeaderText="eDTK Tool"/>
<asp:BoundField DataField="ADMIN" HeaderText="Admin"/>
<asp:buttonfield ButtonType="Button" CommandName="EditUser" HeaderText="Edit User?" Text="Edit" />
<asp:buttonfield ButtonType="Button" CommandName="DelUser" HeaderText="Delete User?" Text="Delete" />
</Columns>
</asp:GridView>
<asp:Button ID="cmdAddNewUser" runat="server" style="z-index: 1; left: 28px; top: 149px; position: absolute; width: 132px" Text="Add New User" />
<asp:Button ID="cmdExit" runat="server" style="position: absolute; top: 22px; left: 729px; height: 45px; width: 54px" Text="Exit" />
</form>
</body>
</html>

請將ButtonField更改為TemplateField

GridView中刪除ButtonField,TemplateField和CommandField的刪除確認

<asp:GridView ID="grdUsers" runat="server" ... >
<Columns>
    ...
   <asp:TemplateField>
     <ItemTemplate>
       <asp:Button ID="Button1" runat="server" 
         CommandName="DelUser" 
         OnClientClick="return confirm('Are you sure you want to delete?');" 
         Text="Delete" />
     </ItemTemplate>
   </asp:TemplateField>
  </Columns>
</asp:GridView>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM