javascript - 从代码后面将值传递给 javascript

标签 javascript c# asp.net webforms

我需要从代码后面将一个值传递给 javascript。

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "<script type='text/javascript'>OpenPopUp();</script>", false);

JS:

function OpenPopUp(parameterValue) {           
        paramframe = parameterValue;            
        openmodal(paramframe);
    }

因此 parameterValue 将具有从后面的代码传递的 ID.Text 值。

我需要将此函数 OpenPopUp 中的代码后面的值传递给 JavaScript。

我尝试了下面的代码,但 JavaScript 没有触发。我是否将正确的值传递给 JS?

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "<script type='text/javascript'>OpenPopUp(" + ID.Text + ");</script>", false);

ID.Text 是 gridview 中 LinkBut​​ton 的 ItemTemplate 值。

最佳答案

试试这个,应该有效

ScriptManager.RegisterStartupScript(this, typeof(string), "script1", "SampleJSFunction('" + vls_variable.Text+ "');", true);

关于javascript - 从代码后面将值传递给 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53813963/

相关文章:

c# - asp.net web 控件的公共(public)属性保存在哪里?

html - 对齐标签组和输入

javascript - Facebook Javascript SDK 产生 SSL 错误

javascript - 扩展篮子 js 功能以动态加载脚本

javascript - 使用 IIFE 作为参数的函数表达式?

java - 执行命令后客户端应用程序应采取什么操作?

c# - Selenium c# - OpenQA.Selenium.StaleElementReferenceException : stale element reference: element is not attached to the page document

c# - Powershell不调用C#对象中的方法

html - 为什么它不在导航栏中显示颜色?

javascript - 使用自定义按钮过滤结果