[英]Pass a file path to a Javascript function from C# code behind
I have this javascript function in a .aspx file. 我在.aspx文件中有此javascript函数。
<script>
function somefun(value)
{
document.getElementById("myFlash").SetVariable("player:jsUrl", value);
document.getElementById("myFlash").SetVariable("player:jsPlay", "");
}
</script>
I'm calling and passing a value to that function inside a onclick event in the code-behind class. 我在代码隐藏类的onclick事件内调用该函数并将值传递给该函数。
protected void DownloadFile(object sender, EventArgs e)
{
string filePath1 = "Audio/songname.mp3";
ScriptManager.RegisterClientScriptBlock(this, typeof(string), "Registering", String.Format("somefun('{0}');", filePath1), true);
}
But when I click the button, I'm getting this error. 但是,当我单击按钮时,出现此错误。 'Unable to get property 'SetVariable' of undefined or null reference' “无法获取未定义或空引用的属性'SetVariable'”
The javascript function is correct and I checked it. javascript函数正确无误,我检查了一下。 I think something is wrong with the way I passing the parameter. 我认为我传递参数的方式有问题。
The javascript function is correct and I checked it. javascript函数正确无误,我检查了一下。
I don't think so. 我不这么认为。 The error message suggests that document.getElementById("myFlash")
return null
, therefore you got an exception when trying to call SetVariable()
on a null reference. 错误消息表明document.getElementById("myFlash")
返回null
,因此在尝试对null引用调用SetVariable()
时遇到异常。 This has nothing to do with the function parameter, at least not yet. 至少与功能参数无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.