0

我必须在 .net 中使用vb6 Msgbox (vbyesno)或类似的东西。我知道我不能使用Msgbox,我应该使用javascript,但问题是,我必须根据查询结果提示该 Messagebox。

例如:

sql= "select * from users where position = 'manager' and id = '1'"
ds = getdataset(sql,db)
If ds.tables(0).rows.count > 0 Then
    If MsgBox("The user is a manager, are you sure you want to delete?", vbYesNo) = vbYes Then
        sql = "delete users where id = '1'"
    End if
End if

这有可能吗?我可以javascript从 .net 代码调用还是有其他方法可以做到这一点?

4

1 回答 1

0

不幸的是,不。您需要了解客户端和服务器端编程的概念。

选择和删除部分是服务器端编程,而 msgBox 是客户端。

您想要的是在 rows.count > 0 时在网页上创建一个按钮;然后处理按钮YES单击甚至删除该行。

[编辑]我觉得我的回答不值得作为答案,所以我在这里添加了更多细节:

创建一个网页名称deleteNow.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="deleteNow.aspx.vb" Inherits="arrow_dynascreen.deleteNow" %>
<!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>
<body>
    <form id="myForm" runat="server">
        Normal webpage content
        <asp:Panel ID="myConfirmationPanel" runat="server">
            The user is a manager, are you sure you want to delete?<br /><br />
            <asp:Button ID="btnConfirmationYes" runat="server" Text="Yes" />
            <asp:Button ID="btnConfirmationNo" runat="server" Text="No" />
        </asp:Panel>
    </form>
</body>
</html>

然后,在后面的代码中,执行以下操作:

Public Class deleteNow   'Or a Partial Class, depending if you are on a WebSite or WebApplication
    Inherits System.Web.UI.Page
    Private Sub deleteNow_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
        myConfirmationPanel.Visible = False 'Set Default to always hide it.

        If Not IsPostBack() Then  'Only check to display confirmation if this is not a PostBack event (ie, when user click on Yes/No button, then don't check/execute this section.
            Dim sql As String = "select * from users where position = 'manager' and id = '1'"
            Dim ds As Data.DataSet '= Data.Sql.getda(sql, db)
            If ds.Tables(0).Rows.Count > 0 Then
                myConfirmationPanel.Visible = True
            End If

        Else
            'Do other things that do not need to wait for confirmation
        End If
    End Sub
    Protected Sub btnConfirmationYes_Click(sender As Object, e As EventArgs) Handles btnConfirmationYes.Click
        'When user click on YES, this section will delete the SQL Row
        Dim sql = "delete users where id = '1'"
    End Sub
    Protected Sub btnConfirmationNo_Click(sender As Object, e As EventArgs) Handles btnConfirmationNo.Click
        'When user click on NO, this section will hide the confirmation panel (and do nothing).
        myConfirmationPanel.Visible = False
    End Sub
End Class
于 2013-01-09T09:52:20.420 回答