从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>"
               );