调用从C#JavaScript函数 [英] Call JavaScript function from C#

查看:137
本文介绍了调用从C#JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function functionname1(arg1, arg2){content}

C#文件

public string functionname(arg)
{
    if (condition)
    {
        functionname1(arg1,arg2); // How do I call the JavaScript function from C#?
    }
}

请参考上面的code和建议我的想法来调用C#的JavaScript函数。

Please refer the above code and suggest me the idea to call a JavaScript function from C#.

推荐答案

如果你想调用JavaScript函数在C#中,这将帮助你:

If you want to call JavaScript function in C#, this will help you:

public string functionname(arg)
{
    if (condition)
    {
        Page page = HttpContext.Current.CurrentHandler as Page;
        page.ClientScript.RegisterStartupScript(
            typeof(Page),
            "Test",
            "<script type='text/javascript'>functionname1(" + arg1 + ",'" + arg2 + "');</script>");
    }
}

这篇关于调用从C#JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆