从vb.net调用Jquery函数时获取类型预期的错误

时间:2018-09-24 07:14:46

标签: javascript jquery vb.net

我正在使用以下代码从代码后面调用Jquery函数。但是在GetType()函数附近获取类型期望的错误。

ScriptManager.RegisterStartupScript(
  Me,
  GetType(),
  "Close Modal Popup",
  "Closepopup();",
  true
)

我使用VB.net作为后台代码。

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

VB有一个GetType关键字,它将在给定数据类型(例如

)的情况下返回Type对象
Dim stringType = GetType(String)

这就是您在此处调用的内容,但是您没有提供数据类型,因此它失败了。大概您实际上是在尝试调用当前对象的GetType方法。在这种情况下,您需要转义标识符,以便不将其解释为关键字:

ScriptManager.RegisterStartupScript(
  Me,
  [GetType](),
  "Close Modal Popup",
  "Closepopup();",
  True
)

或在当前实例上显式调用它:

ScriptManager.RegisterStartupScript(
  Me,
  Me.GetType(),
  "Close Modal Popup",
  "Closepopup();",
  True
)

答案 1 :(得分:0)

ScriptManager.RegisterStartupScript具有这样的重载:

Public Shared Sub RegisterStartupScript(Page, Type, String, String, Boolean)

Public Shared Sub RegisterStartupScript(Control, Type, String, String, Boolean)

错误消息本身表明GetType()方法需要设置类型,因此您应该像下面的示例一样设置该方法:

ScriptManager.RegisterStartupScript(Page, Me.GetType(), "Close Modal Popup", "Closepopup();", True)