![](/img/trans.png)
[英]pass parameter to one function in the code behind in C# from javascript
[英]Pass a file path to a Javascript function from C# code behind
我在.aspx文件中有此javascript函數。
<script>
function somefun(value)
{
document.getElementById("myFlash").SetVariable("player:jsUrl", value);
document.getElementById("myFlash").SetVariable("player:jsPlay", "");
}
</script>
我在代碼隱藏類的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);
}
但是,當我單擊按鈕時,出現此錯誤。 “無法獲取未定義或空引用的屬性'SetVariable'”
javascript函數正確無誤,我檢查了一下。 我認為我傳遞參數的方式有問題。
javascript函數正確無誤,我檢查了一下。
我不這么認為。 錯誤消息表明document.getElementById("myFlash")
返回null
,因此在嘗試對null引用調用SetVariable()
時遇到異常。 至少與功能參數無關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.