Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在.NET部分回发后更新javascript变量_Javascript_Asp.net_Vb.net - Fatal编程技术网

在.NET部分回发后更新javascript变量

在.NET部分回发后更新javascript变量,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,在我的游戏vb.net中,我动态创建了一个按钮,如下所示: Dim nextButton As New ImageButton With nextButton .ID = "nextButton" & directionID.ToString AddHandler .Click, AddressOf directionPath_Click End With 在游戏中,当点击按钮时,它会触发并更新一个名为directionPath的变量 当我运行VisualStudi

在我的游戏vb.net中,我动态创建了一个按钮,如下所示:

Dim nextButton As New ImageButton

With nextButton 
    .ID = "nextButton" & directionID.ToString
    AddHandler .Click, AddressOf directionPath_Click
End With
在游戏中,当点击按钮时,它会触发并更新一个名为directionPath的变量

当我运行VisualStudio调试器时,该部分工作正常

但是,我需要使用directionPath的值更新javascript中的变量clientside

每当我单击按钮时,javascript部分都不会获得更新的值

我阅读了部分回帖,尝试了很多方法,但都没有效果

这可能吗


谢谢

服务器端代码可以注册JavaScript代码,这些代码将在使用类进行回发后在客户端上运行。有许多可用的
RegisterXXX
方法,我从未完全确定在哪种情况下使用哪种方法,但我已经成功地使用了(尽管即使是这样,对于是否要传入页面或某些控件(例如,
UpdatePanel
作为第一个参数)也很困惑)

因此,您可能需要进行一些实验,但在您的
directionPath\u Click
方法中尝试类似的方法:

ScriptManager.RegisterStartupScript(
    Me, ' The page
    Me.GetType(), ' The type for the page class
    "MyScriptKey", ' A unique identifier for the script
    "myjsvar = '" & myservervar.ToString() & "';", ' The JavaScript to run
    True ' Add <script> tags around the code
)
ScriptManager.RegisterStartupScript(
“我,”页面上写道
Me.GetType(),'页类的类型
“MyScriptKey”,脚本的唯一标识符
“myjsvar=”&myservervar.ToString()&“;”,“要运行的JavaScript
True“在代码周围添加标记
)

您正试图通过javascript更改服务器端处理程序?不如把javascript用来改变这一点的标准推到服务器代码中的post和分支上。对我来说,这听起来简单了一百万倍。@asawyer不,我只需要在服务器变量被更新时获取它,然后触发onclick事件。感谢您可以尝试在
directionPath\u单击设置变量的
中注册启动脚本。我认为语法类似于
ScriptManager.RegisterStartupScript(Me,Me.GetType(),“MyScriptKey”,“myjsvar=”,&myservervar.ToString()&“;”,True)
。第四个参数是回发后要运行的JavaScript。@Mark能否请您在回答中对此进行扩展,以便格式更易于阅读?我想它可能有用…谢谢!