0

JavaScript関数内でVB.NETメソッドを呼び出すのを手伝ってくれる人はいますか? 私のメソッドは共有/静的ではなく、何も返しません。データをデータベースに保存し、ユーザーをリダイレクトするだけです。助けてください、これが私のコードです:

VB法

  Public Function SaveVehicles()
          Dim res As Boolean
             If res = True Then
            Dim sModel As String = cboModel.SelectedValue
            Dim sVariant As String = cboVariant.SelectedValue
            Dim sColor As String = cboColor.SelectedValue

            cboModel.SelectedValue = sModel
            cboVariant.SelectedValue = sVariant
            cboColor.SelectedValue = sColor


            Dim oData As New WebServVehSwapping
            Dim strSql As String
            Dim sDealer As String
            Dim sUserName As String

            'sDealer = "TBP01"
            sDealer = Trim(Request.QueryString("dealercode"))
            If sDealer = "" Then sDealer = "TBP01"
            sUserName = "User1"

            '------------------------------------------
            strSql = oData.InsertTblRequirement( _
              sDealer _
             , Now.ToString _
             , sUserName _
             , cboColor.Text.Trim _
             , cboModel.Text.Trim _
             , cboVariant.Text.Trim, "Open")
            MsgBox("OKAY")
            Response.Redirect("MyRequirements.aspx?DealerCode=" & sDealer)
        Else
            'do Nothing
        End If
    End Function

ここに私のJavascript関数があります

   function ConfirmView()
    {   
        var Ok = confirm('There is/are existing vehicle(s) in Network Vehiches for sale, View Vehicle(s)?');
        if(Ok==true)
        {

       location.href = 'NetworkVehiclesforSale.aspx';
        return false;
        }
        else if (Ok!=true)
        {

         //THE VB METHOD GOES HERE     
      }
}

コールバック ハンドラーを試してみましたが、何か/文字列を返す関数でのみ動作します

私は Pagemethod を試しましたが、静的/共有関数でのみ機能します。私を助けてください、私は本当にそれが必要です。どうぞ。ありがとう

4

2 に答える 2

1

.Net Web サービスはマジックを実行できません。つまり、サーバー上の Ajax 要求に対してリダイレクト応答を発行して、ページ全体がリダイレクトされることを期待することはできません。発生する唯一のことは、Ajax 呼び出しが別のページにリダイレクトされ、そこからデータを取得しようとすることです。クライアント ブラウザでページを変更する場合は、JavaScript を使用してクライアント側で変更する必要がありますdocument.location = url_returned_by_your_function_through_ajax_call

于 2011-05-23T00:15:16.983 に答える
1

「Windows Communication Foundation サービスの構築の概要」を読むことをお勧めします - http://msdn.microsoft.com/en-us/library/aa480190.aspx

特に: 「WCF 3.5 を使用した RESTful Web サービスの設計と構築のガイド」 - http://msdn.microsoft.com/en-us/library/dd203052.aspx

また、jQuery など、RESTful Web サービスの呼び出しを容易にする JavaScript ライブラリーを確認してください - http://www.jquery.com/

jQuery を使用すると、次のようにサーバー側の VB.NET コードを呼び出すことができます。

$.ajax({  
    type: "GET",  
    contentType: 'text/json',  
    dataType: 'json',  
    url: "https://URL-TO-SERVICE-HERE/...",  
    timeout: 10000,  
    error: function () {  

        // Deal with the error  

    },  
    success: function (data) {  

        // Do something with the result
        // Example:
        if (data.dealerCode) 
            location.href = 'MyRequirements.aspx?DealerCode=' + data.dealerCode;


    }  
});  
于 2011-05-23T00:11:59.877 に答える