繁体   English   中英

如何从asp.net中的代码后面调用javascript?

[英]how to call javascript from code behind in asp.net?

我的页面中有Java脚本,我想从功能后面的vb.net代码中调用它,并且不想调用它(onload或onclick或任何类似的事件),但是我想从执行looping.so的函数中调用它它将运行一次以上

您需要这样做:

 ' Define the name and type of the client scripts on the page. 
    Dim csname1 As [String] = "PopupScript"
    Dim cstype As Type = Me.[GetType]()

    ' Get a ClientScriptManager reference from the Page class. 
    Dim cs As ClientScriptManager = Page.ClientScript

    ' Check to see if the startup script is already registered. 
    If Not cs.IsStartupScriptRegistered(cstype, csname1) Then
        Dim cstext1 As New StringBuilder()
        cstext1.Append("<script type=text/javascript> getval('elementid') </") 'Your javascript function
        cstext1.Append("script>")

        cs.RegisterStartupScript(cstype, csname1, cstext1.ToString())
    End If

资源。

使用SignalR实际上可以做到这一点。

https://github.com/SignalR/SignalR

很酷的东西。

持久的连接听起来像您想要的那样。

https://github.com/SignalR/SignalR/wiki/PersistentConnection

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM