문제

I have to use vb6 Msgbox (vbyesno) in .net or something similar to that. I know I can't use Msgbox and I should use javascript but the problem is, I have to prompt that Messagebox based on the result of a query.

For example:

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

Is this somehow possible? Can I call javascript from the .net code or is there any other way to do this?

도움이 되었습니까?

해결책

Unfortunately No. You need to understand the concept of client-side and server-side programming.

The select & delete portion is server-side programming, while the msgBox is client-side.

What you want is to create a button on the webpage when rows.count > 0; then handle the buttonYES click even to delete the row.

[Edit] I felt my response does not merit as an answer, so I've added a bit more details here:

Create a webPage name 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>

Then, at the Code behind, do this:

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top