[英]Passing data from code behind (c#) to javascript
I have seen the below piece of code which apparently is a techiqnue to pass variables from code behind into javascript. 我看过下面的代码,这显然是一种将变量从代码传递到javascript中的技术。 Use either ScriptManager to register a function and pass it data during Page_Load
: 使用任一ScriptManager来注册一个函数,并在Page_Load
期间传递其数据:
ScriptManager.RegisterStartupScript(this.GetType(), "Set","get("Test();",true);
Could someone please explain how this could be used to pass data? 有人可以解释一下如何使用它来传递数据吗?
This isn't a get or set in JavaScript, this is a startup script that will run when the DOM loads client-side. 这不是JavaScript中的获取或设置,它是一个启动脚本,将在DOM加载客户端时运行。 It's a basic JavaScript call to a method named get
that receives two parameters. 这是对名为get
的方法的基本JavaScript调用,该方法接收两个参数。 The first is a string, and it's getting that value passed into it by calling a method server-side named Test
. 第一个是字符串,它通过调用名为Test
服务器端方法来将值传递给它。 The second is a boolean value. 第二个是布尔值。
Now, two things, I don't know how this is even compiling. 现在,有两件事,我什至不知道该如何编译。 But second, there is a method called get
in one of your JavaScript files. 但是第二,在您的一个JavaScript文件中有一种名为get
的方法。 That's what you're looking for. 这就是您要寻找的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.