1

データベースからアクセスした変数を含む関数があります。以下に示す方法で、その変数を URL と連結しようとしています。

PopupWindow=window.open('Http://' + svrname +'/Quoteman/DatePicker.aspx?Ctl=' + ctl,'DatePicker',settings);

コードをコンパイルしようとすると、エラーが発生します。
関数は次のとおりです。

     Public Function getserverName() As String
    Dim connection As SqlConnection
    Dim command As SqlCommand
    Dim readData As SqlDataReader
    Dim path As String
    path = ""

    connection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("getServer"))
    connection.Open()
    command = New SqlCommand("select [Email_Notification_Date] from GlobalDB where [Email_Notification_Date]='Batman'", connection)
    readData = command.ExecuteReader
    While readData.Read()
        path = readData.Item("Email_Notification_Date")
    End While
    connection.Close()
    Return path
End Function

そして、ここで関数を呼び出そうとしています:

    function PopupPicker(ctl,w,h)
{
var PopupWindow = null;
var serverName = new getServername;
svrname = serverName.getServername;
    settings='width='+ w + ',height='+ h + ',location=no,directories=no, menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';
    PopupWindow=window.open('Http://' + svrname +'/Quoteman/DatePicker.aspx?Ctl=' + ctl,'DatePicker',settings);
    PopupWindow.focus();
}

PS関数は値を返します。

編集: 申し訳ありませんが、javascript から VB 関数を呼び出そうとしていることを忘れていました。これは、エラーから得られるウィンドウです。

Unhandled exception at line 200, column 5 in http://localhost:50209/Admin/EmployeeAssets.aspx || 0x800a1391 - JavaScript runtime error: 'getServername' is undefined

編集:関数に引数を追加したところ、インスタンスを介して共有メンバー、定数メンバー、列挙型メンバー、またはネストされた型にアクセスできるようになりました。修飾式は評価されません。

ここに私の修正されたコードがあります

    <System.Web.Services.WebMethod()>
Public Shared Function getServerName(suffix As String) As String
    Dim connection As SqlConnection
    Dim command As SqlCommand
    Dim readData As SqlDataReader
    Dim path As String
    path = ""

    connection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("getServer"))
    connection.Open()
    command = New SqlCommand("select [Email_Notification_Date] from GlobalDB where [Email_Notification_Date]='Batman'", connection)
    readData = command.ExecuteReader
    While readData.Read()
        path = readData.Item("Email_Notification_Date")
    End While
    connection.Close()
    Return ("http://") + path + suffix
End Function

メインファイルを編集して、パラメーターとして文字列を含めました。

PopupWindow=window.open(<%= (New getServerName).getserverName("/Quoteman/DatePicker.aspx?Ctl=") %> + ctl,'DatePicker',settings);
4

3 に答える 3