从后面的代码中,我想调用JavaScript函数并传递值 [英] From Code behind I want to call JavaScript function and pass the value
本文介绍了从后面的代码中,我想调用JavaScript函数并传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,
从后面的代码中,我想调用JavaScript函数并传递值
我已经在下面的代码中编写了一个代码,如下所示
背后的代码:
Dear Friends,
From Code behind I want to call JavaScript function and pass the value
I have written a code in code behind as follows
Code Behind:
Disp=Disp+"<img src="path" önClick="fun_Call_JavaScript("+str_val+")">"
从查询中检索str_val.
从后面的代码中,我想调用JavaScript函数并传递值(str_val)
str_val is retrieved from query.
From Code behind I want to call JavaScript function and pass the value(str_val)
function fun_Call_JavaScript(a)
{
alert(a)
}
但这给出了未定义的错误.
请提出如何获取值的建议.
But it gives a error as undefined.
Kindly suggest, how to get the value.
推荐答案
看看执行此操作的标准方法:
在ASP.NET中注册客户端脚本 [
Look at the standard way of doing this:
Register Client script in ASP.NET[^]
这应该可以完成工作:
Page.RegisterStartupScript("starScript","fun_Call_JavaScript(" + a +'');");
This should do the job:
Page.RegisterStartupScript("starScript", "fun_Call_JavaScript(''" + a + "'');");
使用:
MSDN:RegisterClientScriptBlock方法 [ MSDN:RegisterStartupScript方法 [如何使用RegisterClientScriptBlock& RegisterStartupScript [ ^ ]
从服务器注入javascript-示例 [
using:
MSDN: RegisterClientScriptBlock Method[^] OR
MSDN: RegisterStartupScript Method[^]
Using them, you can inject the scripts into a page from server side and based on certain condition (and specific to page.)
For samples on how to use it: How to Use RegisterClientScriptBlock & RegisterStartupScript[^]
Inject javascript from server - Sample[^]
这篇关于从后面的代码中,我想调用JavaScript函数并传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文