带有空值的Jquery对话框

带有空值的Jquery对话框,jquery,asp.net,vb.net,Jquery,Asp.net,Vb.net,我的ASP.NET页面上有一个jQuery UI对话框: $(function () { var dialog, fascicolo = getQuerystring("fascicolo"), annotazione = $("#nota").val(); function addUser() { var nota = {};

我的ASP.NET页面上有一个jQuery UI对话框:

        $(function () {
            var dialog,
              fascicolo = getQuerystring("fascicolo"),
              annotazione = $("#nota").val();

            function addUser() {
                var nota = {};
                nota.fascicolo = fascicolo;
                nota.notastr = annotazione;
                $.ajax({
                ...
                    }
                });
                dialog.dialog("close");
            }

            dialog = $("#dialog-form").dialog({
                autoOpen: false,
                height: 300,
                width: 350,
                modal: true,
                buttons: {
                    "Inserisci la nota": addUser,
                    Cancel: function () {
                        dialog.dialog("close");
                    }
                },
                close: function () {
                }
            });
            $("#create-user").button().on("click", function () {
                event.preventDefault();
                dialog.dialog("open");
            });
        });
  </script>
这就是ajax所称的WebMethod:

<WebMethod()> _
<ScriptMethod()> _
     Public Shared Sub SaveNota(nota As nota)
    Dim conString As String =           ConfigurationManager.ConnectionStrings("connMySql").ConnectionString
    Dim myConnection As MySqlConnection = New MySqlConnection(conString)

    Dim stringa_ins As String = "INSERT INTO `note_fascicolo`(`fascicolo`, `note`) VALUES (@fascicolo,@nota)"

    Dim dbcomm As New MySqlCommand(stringa_ins, myConnection)

    dbcomm.Parameters.Add("@fascicolo", MySqlDbType.Int32)
    dbcomm.Parameters.Add("@nota", MySqlDbType.VarChar)

    dbcomm.Parameters("@fascicolo").Value = nota.fascicolo
    dbcomm.Parameters("@nota").Value = nota.notastr

    Dim ident As Integer

    Try
        myConnection.Open()
        ident = dbcomm.ExecuteScalar()

    Catch ex As Exception
        'Response.Write(ex.Message)
        'Response.End()

    End Try

    myConnection.Close()
End Sub

 Public Class nota
    Public Property fascicolo() As String
        Get
            Return _fascicolo
        End Get
        Set(value As String)
            _fascicolo = value
        End Set
    End Property
    Private _fascicolo As String
    Public Property notastr() As String
        Get
            Return _notastr
        End Get
        Set(value As String)
            _notastr = value
        End Set
    End Property
    Private _notastr As String
End Class
_
_
公共共享子SaveNota(nota作为nota)
Dim解析为String=ConfigurationManager.ConnectionString(“connMySql”).ConnectionString
Dim myConnection As MySqlConnection=新建MySqlConnection(构造)
Dim stringa_ins As String=“插入'note_fascicolo'('fascicolo','note`)值(@fascicolo,@nota)”
Dim dbcomm作为新的MySqlCommand(stringa_-ins,myConnection)
dbcomm.Parameters.Add(“@fascicolo”,MySqlDbType.Int32)
添加(“@nota”,MySqlDbType.VarChar)
dbcomm.Parameters(“@fascicolo”).Value=nota.fascicolo
dbcomm.Parameters(“@nota”).Value=nota.notastr
作为整数的Dim ident
尝试
myConnection.Open()
ident=dbcomm.ExecuteScalar()
特例
'响应.写入(例如消息)
'Response.End()
结束尝试
myConnection.Close()
端接头
公共类公证员
公共属性fasicolo()作为字符串
得到
返回
结束
设置(值为字符串)
_筋膜=数值
端集
端属性
Private _fascicolo作为字符串
公共属性notastr()作为字符串
得到
返回\u notastr
结束
设置(值为字符串)
_notastr=值
端集
端属性
Private\u notastr作为字符串
末级

也发布你的ajax调用。我添加了ajax调用,但我不清楚(至少对我来说)你想要实现什么。请详细说明你想附加什么?什么,何时何地。对话框打开时会出现一些问题,但具体是什么?为什么要使用
window.location.reload()?使用ajax的优点是不需要重新加载页面!我想用ajax在mysql数据库中插入一个新的记录nota。这些记录在gridview中,我会在重新加载时刷新。也发布您的ajax调用。我添加了ajax调用,thanksIt不清楚(至少对我来说)您想要实现什么。请详细说明你想附加什么?什么,何时何地。对话框打开时会出现一些问题,但具体是什么?为什么要使用
window.location.reload()?使用ajax的优点是不需要重新加载页面!我想用ajax在mysql数据库中插入一个新的记录nota。这些记录在我重新加载时刷新的gridview中。
function addUser() {
                var nota = {};
                nota.fascicolo = fascicolo;
                nota.notastr = annotazione;
                $.ajax({
                    type: "POST",
                    url: "dettagliofascicolo2.aspx/SaveNota",
                    data: '{nota: ' + JSON.stringify(nota) + '}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        alert("Nota inserita correttamente!");
                        window.location.reload();
                    }
                });
                dialog.dialog("close");
            }
<WebMethod()> _
<ScriptMethod()> _
     Public Shared Sub SaveNota(nota As nota)
    Dim conString As String =           ConfigurationManager.ConnectionStrings("connMySql").ConnectionString
    Dim myConnection As MySqlConnection = New MySqlConnection(conString)

    Dim stringa_ins As String = "INSERT INTO `note_fascicolo`(`fascicolo`, `note`) VALUES (@fascicolo,@nota)"

    Dim dbcomm As New MySqlCommand(stringa_ins, myConnection)

    dbcomm.Parameters.Add("@fascicolo", MySqlDbType.Int32)
    dbcomm.Parameters.Add("@nota", MySqlDbType.VarChar)

    dbcomm.Parameters("@fascicolo").Value = nota.fascicolo
    dbcomm.Parameters("@nota").Value = nota.notastr

    Dim ident As Integer

    Try
        myConnection.Open()
        ident = dbcomm.ExecuteScalar()

    Catch ex As Exception
        'Response.Write(ex.Message)
        'Response.End()

    End Try

    myConnection.Close()
End Sub

 Public Class nota
    Public Property fascicolo() As String
        Get
            Return _fascicolo
        End Get
        Set(value As String)
            _fascicolo = value
        End Set
    End Property
    Private _fascicolo As String
    Public Property notastr() As String
        Get
            Return _notastr
        End Get
        Set(value As String)
            _notastr = value
        End Set
    End Property
    Private _notastr As String
End Class