从ASP.NET背后的代码中调用Javascript函数 [英] Calling Javascript function from code behind ASP.NET
本文介绍了从ASP.NET背后的代码中调用Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在单击按钮时从后面的代码中调用其自身文件中的javascript方法。
I'm attempting to call a javascript method in its own file from code behind on a button click.
aspx文件
protected void Next_Click(object sender, EventArgs e)
{
if (hidden.Value == "")
{
Response.Write(@"<script language='javascript'>drawImage();</script>");
}
}
js文件
function drawImage() {
context.drawImage(video, 0, 0, 320, 240);
var imgBase = canvas.toDataURL('image/jpeg');
document.getElementById("hidden").value = imgBase;
}
问题是这不会调用绘制图像方法,我怀疑这是原因js文件是它自己的文件,但我不确定。
The problem is that this wont call the draw image method, i suspect it's cause the js file is its own file but i'm not sure.
您能提供的任何帮助将不胜感激。
Any help you could give would be greatly appreciated.
推荐答案
请参见 http:// msdn.microsoft.com/de-de/library/z9h4dk8y.aspx
尝试
string jquery = "drawImage();"
ClientScript.RegisterStartupScript(typeof(Page), "a key",
"<script type=\"text/javascript\">"+ jquery +"</script>"
);
这篇关于从ASP.NET背后的代码中调用Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文