如何使用 vb.net 在 asp net webforms 中显示带有是或否的消息框?

罗杰金

在向表中插入记录之前,系统会首先检查此人的名字和姓氏是否已经存在。如果此人已存在,则会出现一个带有是或否按钮的消息框,询问用户是否要继续插入记录。我尝试了以下代码:

Imports ChurchMIS.Data
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Web
Imports System.Web.Security
Imports System.Data.SqlClient
Namespace ChurchMIS.Rules

Partial Public Class IndividualBusinessRules
    Inherits ChurchMIS.Data.BusinessRules

    ''' <summary>
    ''' This method will execute in any view for an action
    ''' with a command name that matches "SQL".
    ''' </summary>
    <Rule("r107")>  _
    Public Sub r107Implementation( _
                ByVal individualId As Nullable(Of Integer),  _
                ByVal firstName As String,  _
                ByVal lastName As String,  _
                ByVal dateOfBirth As Nullable(Of DateTime),  _
                ByVal addressTypeId As Nullable(Of Integer),  _
                ByVal suburb As String,  _
                ByVal streetAddress As String,  _
                ByVal postCode As Nullable(Of Integer),  _
                ByVal contactInfoTypeId As Nullable(Of Integer),  _
                ByVal contactNo As String,  _
                ByVal fullName As String,  _
                ByVal individualTypeId As Nullable(Of Integer),  _
                ByVal state As String,  _
                ByVal dateOfBaptism As Nullable(Of DateTime),  _
                ByVal dateOfTransfer As Nullable(Of DateTime),  _
                ByVal email As String,  _
                ByVal faithStatus As Nullable(Of Integer),  _
                ByVal noOfVisits As Nullable(Of Integer),  _
                ByVal name As String,  _
                ByVal name_1 As String,  _
                ByVal name_2 As String)
        'This is the placeholder for method implementation.
        Dim con As SqlConnection = New SqlConnection("Data     Source=CNEPHILS;Initial Catalog=ChurchMIS;User ID=sa;Password=Cn$phil$")

        Dim theQuery As String = "SELECT * FROM Individual WHERE  FirstName=@FirstName AND LastName=@LastName"
        Dim cmd1 As SqlCommand = New SqlCommand(theQuery, con)
        cmd1.Parameters.AddWithValue("@FirstName", firstName)
        cmd1.Parameters.AddWithValue("@LastName", lastName)

        Using reader As SqlDataReader = cmd1.ExecuteReader()
            If reader.HasRows Then
                ' person already exists
                    Dim result As Integer=

                Dim result As Integer = MessageBox.Show("message",  "caption", MessageBoxButtons.YesNoCancel)
                If result = DialogResult.Cancel Then
                    MessageBox.Show("Cancel pressed")
                ElseIf result = DialogResult.No Then
                    MessageBox.Show("No pressed")
                ElseIf result = DialogResult.Yes Then
                    Dim cmd As SqlCommand = New SqlCommand("exec  spInsertIndividual @FirstName,@LastName,@DateOfBirth,@Suburb,@StreetAddress,@PostCode,@State,@AddressTypeId,@ContactInfoTypeId,@ContactNo,@IndividualTypeId,@Email,@FaithStatus,@DateOfBaptism,@DateOfTransfer", con)
                    cmd.ExecuteNonQuery()
                    MsgBox("Records Successfully Added!", MsgBoxStyle.Information)
                End If
            Else
                ' person does not exist, add them
                Dim cmd As SqlCommand = New SqlCommand("exec spInsertIndividual @FirstName,@LastName,@DateOfBirth,@Suburb,@StreetAddress,@PostCode,@State,@AddressTypeId,@ContactInfoTypeId,@ContactNo,@IndividualTypeId,@Email,@FaithStatus,@DateOfBaptism,@DateOfTransfer", con)
                cmd.ExecuteNonQuery()
                MsgBox("Records Successfully Added!", MsgBoxStyle.Information)
            End If
        End Using

        con.Close()

    End Sub
End Class
End Namespace

但是,我提出了一个错误“MessageBox 未声明......保护级别。”

希望有人能帮忙。谢谢!

普拉巴

@罗杰。我认为您正在使用 Web 应用程序。试试这个,在你的 .aspx 页面的 head 标签内添加这个脚本。

<script type="text/javascript">
        function SomeMethod() {
            try {
                var result = true;
                var obj = {};
                obj.Firstname = $('#<%=txtfirstname.ClientID %>').val();
                obj.Lastname = $('#<%=txtlastname.ClientID %>').val();
                $.ajax({
                    type: "POST",
                    data: JSON.stringify(obj),
                    url: "yourformname.aspx/yourmethodname",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async:false,
                    success: function (response) {
                        if (response.d.toString() == "true") {
                                if (confirm("first name and last name of the person is already exists?")) {
                                    result = true;
                                    // insert the user name
                                }
                                else {
                                    result = false;

                                }
                        }
                        else {

                        }
                    },
                    failure: function (response) {
                        alert(response.d);
                    }
                });
            }
            catch (e) {
                alert(e);
            }
            return result;
        }
    </script>

在按钮单击事件中调用 javascript 函数。如果您使用 RequiredFieldValidator 进行验证,请使用 Page_ClientValidate() 否则请删除按钮 onclick 事件中的 Page_ClientValidate() 函数。

<asp:Button ID="btnbutton" CssClass="Designclass" OnClientClick="if(Page_ClientValidate()) return SomeMethod();"
                                        runat="server" Text="Generate" />

在您的 .aspx.vb 页面中创建以下 Web 方法

 <System.Web.Services.WebMethod()>
Public Shared Function Checkuserexists(ByVal Firstname As String, ByVal Lastname As String) As String
    'write your code for checking firstname and last name
     If exists > 0 Then
        Return true
    Else
        Return False
    End If
End Function

通过使用 Checkuserexists 方法检查名字和姓氏是否存在于数据库中。如果名字和姓氏存在,则返回 true 并要求符合消息。如果单击是,则将值插入到数据库中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

<asp:Asp.Net Webforms中的ScriptManager,它如何工作?

来自分类Dev

如何在asp.net中显示“是”或“否”消息框?

来自分类Dev

如何具有多个ASP.Net Webforms缓存版本?

来自分类Dev

从Asp.Net Webforms显示Bootstrap模式

来自分类Dev

ASP.NET WebForms中的异步事件

来自分类Dev

ASP.NET WebForms中的FileUpload formData

来自分类Dev

ASP.NET WebForms中的FileUpload formData

来自分类Dev

如何使用 ASP.NET WebForms 中的 JavaScript 从 FormView 中的 DropDownList 获取文本到 TextBox 中?

来自分类Dev

如何使用iis在Asp.net Webforms现有项目中启用Webapi?

来自分类Dev

使用 VB.NET 的构造函数的 Webforms Autofac 参数

来自分类Dev

如何使用jquery或javascript在asp.net webforms母版页中激活当前菜单项

来自分类Dev

如何使用 ASP.NET C# WebForms 从多个安全组中获取成员?

来自分类Dev

如何在 ASP.Net Webforms 中执行 For 在每次迭代中添加带有 <asp> 标记的元素?

来自分类Dev

VB.NET中的C#Webforms用户控件

来自分类Dev

带有角度回发的ASP.NET WebForms

来自分类Dev

ASP.Net WebForms 中的 Gravatar 显示默认图像

来自分类Dev

使用Webforms的ASP.NET中的静态控件和动态控件有什么区别

来自分类Dev

ASP.NET WebForms-如何授权对页面的访问

来自分类Dev

如何允许CORS用于ASP.NET WebForms终结点?

来自分类Dev

在ASP.NET中使用Unity.WebForms

来自分类Dev

使用IoC的ASP.NET WebForms动态加载WebUserControls

来自分类Dev

我应该使用ASP.NET WebForms还是MVC

来自分类Dev

显示数据asp.net WebForms时出错

来自分类Dev

如何防止用户单击ASP.NET Webforms的gridview中多次启动文件下载的图像按钮?

来自分类Dev

使用WebForms的ASP.Net Identity到现有SQL数据库

来自分类Dev

了解ASP .NET(WebForms)中的错误处理

来自分类Dev

无法在ASP.NET Webforms中异步运行任务

来自分类Dev

Asp.Net Webforms自定义UserControl中的事件

来自分类Dev

LinqToTwitter问题与ASP.NET Webforms中的API连接

Related 相关文章

  1. 1

    <asp:Asp.Net Webforms中的ScriptManager,它如何工作?

  2. 2

    如何在asp.net中显示“是”或“否”消息框?

  3. 3

    如何具有多个ASP.Net Webforms缓存版本?

  4. 4

    从Asp.Net Webforms显示Bootstrap模式

  5. 5

    ASP.NET WebForms中的异步事件

  6. 6

    ASP.NET WebForms中的FileUpload formData

  7. 7

    ASP.NET WebForms中的FileUpload formData

  8. 8

    如何使用 ASP.NET WebForms 中的 JavaScript 从 FormView 中的 DropDownList 获取文本到 TextBox 中?

  9. 9

    如何使用iis在Asp.net Webforms现有项目中启用Webapi?

  10. 10

    使用 VB.NET 的构造函数的 Webforms Autofac 参数

  11. 11

    如何使用jquery或javascript在asp.net webforms母版页中激活当前菜单项

  12. 12

    如何使用 ASP.NET C# WebForms 从多个安全组中获取成员?

  13. 13

    如何在 ASP.Net Webforms 中执行 For 在每次迭代中添加带有 <asp> 标记的元素?

  14. 14

    VB.NET中的C#Webforms用户控件

  15. 15

    带有角度回发的ASP.NET WebForms

  16. 16

    ASP.Net WebForms 中的 Gravatar 显示默认图像

  17. 17

    使用Webforms的ASP.NET中的静态控件和动态控件有什么区别

  18. 18

    ASP.NET WebForms-如何授权对页面的访问

  19. 19

    如何允许CORS用于ASP.NET WebForms终结点?

  20. 20

    在ASP.NET中使用Unity.WebForms

  21. 21

    使用IoC的ASP.NET WebForms动态加载WebUserControls

  22. 22

    我应该使用ASP.NET WebForms还是MVC

  23. 23

    显示数据asp.net WebForms时出错

  24. 24

    如何防止用户单击ASP.NET Webforms的gridview中多次启动文件下载的图像按钮?

  25. 25

    使用WebForms的ASP.Net Identity到现有SQL数据库

  26. 26

    了解ASP .NET(WebForms)中的错误处理

  27. 27

    无法在ASP.NET Webforms中异步运行任务

  28. 28

    Asp.Net Webforms自定义UserControl中的事件

  29. 29

    LinqToTwitter问题与ASP.NET Webforms中的API连接

热门标签

归档