我有一个函数,其中包含我从数据库访问的变量。我正在尝试以下述方式将该变量与 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);