我有一個函數,其中包含我從數據庫訪問的變量。 我想以下面陳述的方式將該變量與URL連接起來。將變量傳遞到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();
}
附:該函數確實會返回一個值。
編輯:對不起,忘了說我想從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);
你是從JavaScript調用VB.NET代碼? – Satpal
是的,對不起。忘記指定語言 – GeoffWilson
請指定錯誤並可能發佈日誌。它是一個編譯或運行時錯誤? –