vb.net-执行JavaScript时出错
我想使用vb.net执行JS代码,但我得到错误“ScriptManager”不是“UI”的成员vb.net-执行JavaScript时出错,vb.net,shared-libraries,Vb.net,Shared Libraries,我想使用vb.net执行JS代码,但我得到错误“ScriptManager”不是“UI”的成员 System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me,Me.GetType(),“Script”,“function();”,True) ScriptManager是UI的一部分,UI是System.Web的一部分。我已导入System.Web dll,但错误仍然存在 我还尝试了System.Web.UI.Page.ClientScript.
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me,Me.GetType(),“Script”,“function();”,True)
ScriptManager是UI的一部分,UI是System.Web的一部分。我已导入System.Web dll,但错误仍然存在
我还尝试了System.Web.UI.Page.ClientScript.RegisterStartupScript(Me.GetType(),“Script”,“function();”,True)
,但它返回错误对非共享成员的引用需要对象引用
我是不是遗漏了什么
编辑:我正在使用netframework4尝试使用
ClientScriptManager:
Page.ClientScript.RegisterStartupScript(
Me, Me.GetType(), "Script", "function();", True);
尝试下面的示例
<asp:Button ID="btnUpdate" Text="Update Time" runat="server" OnClick="UpdateTime" />
<asp:Label ID="lblTime" runat="server" />
<script type="text/javascript">
function UpdateTime(time) {
document.getElementById("<%=lblTime.ClientID %>").innerHTML = time;
}
</script>
Protected Sub UpdateTime(sender As Object, e As EventArgs)
Dim time As String = DateTime.Now.ToString("hh:mm:ss tt")
Dim script As String = "window.onload = function() { UpdateTime('" & time & "'); };"
ClientScript.RegisterStartupScript(Me.GetType(), "UpdateTime", script, True)
End Sub
函数更新时间(时间){
document.getElementById(“”).innerHTML=time;
}
受保护的子更新时间(发件人作为对象,e作为事件参数)
Dim time As String=DateTime.Now.ToString(“hh:mm:ss tt”)
Dim脚本为String=“window.onload=function(){UpdateTime(“&time&”);}
RegisterStartupScript(Me.GetType(),“UpdateTime”,脚本,True)
端接头