Javascript C#:以数据作为指令从代码隐藏执行脚本
我尝试使用javascript从代码隐藏中引用数据,代码如下:Javascript C#:以数据作为指令从代码隐藏执行脚本,javascript,c#,Javascript,C#,我尝试使用javascript从代码隐藏中引用数据,代码如下: ClientScript.RegisterStartupScript(Page.GetType(), "validation", "************ some code ******** <h1>${data.features[0].properties.BLOCK}</h1></script>"); ClientScript.RegisterStartupScript(Page.Get
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "************ some code ******** <h1>${data.features[0].properties.BLOCK}</h1></script>");
ClientScript.RegisterStartupScript(Page.GetType(),“validation”,“*************某些代码******${data.features[0].properties.BLOCK}”);
此部分${data.features[0].properties.BLOCK}
不例外
如何编写它?您正在模板字符串(
${data.features[0].properties.BLOCK}
)中使用占位符,而不使用反勾号。
此外,正如@Gauravsa所指出的,应该使用
RegisterClientScriptBlock
注册脚本,因为它是一个片段,而不是js
文件。data.features[0].properties.BLOCK
这不能从代码中引用。数据是脚本中声明的变量,然后在脚本中引用它。如果不是那么简单,那么您的问题就不清楚了。将RegisterStartupScript更改为RegisterClientScriptBlock很高兴它有所帮助!