如何从C#代码访问javascript函数? [英] How to access the javascript function from C# code?
本文介绍了如何从C#代码访问javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的java脚本函数
this is my java script function
function OnClientSeriesClicked(sender, eventArgs)
{
eventArgs.get_dataItems();
}
这是我的C#代码
this is my C# code
chrtPie.OnClientSeriesClicked += new EventHandler(OnClientSeriesClicked());
chrtPie.Legend.Appearance.Visible = true;
chrtPie.Legend.Appearance.Position = ChartLegendPosition.Left;
chrtPie.Legend.Appearance.TextStyle.FontFamily = "sans-serif";
chrtPie.Legend.Appearance.TextStyle.FontSize = 12;
chrtPie.Height = 50;
chrtPie.Width = 50;
private EventHandler OnClientSeriesClicked()
{
//from here i want to call that javascript function
}
这里这个radhtml图表是动态创建的。
所以任何人都可以帮助我吗?
提前谢谢。
here this radhtml chart is created dynamically.
So any one can help me?
Thanks in advance.
推荐答案
可能你可以做这样的事情 -
May be you can do something like this-
//find out sender
//find out eventArgs
Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "OnClientSeriesClicked("+sender+","+eventArgs+");", true);
您可以从后端编写java脚本在C#中。这样你就可以在java脚本函数中传递你的变量。
看看链接:
http://stackoverflow.com/ question / 19288428 / how-to-write-this-javascript-coding-in-c-sharp-code-behind
You can write java script from backend in C#. In this way you can pass your variable in java script function.
Look at the link:
http://stackoverflow.com/questions/19288428/how-to-write-this-javascript-coding-in-c-sharp-code-behind
Page page = HttpContext.Current.CurrentHandler as Page;
page.ClientScript.RegisterStartupScript(typeof(Page), "Test", "<script type='text/javascript'>functionname1(" + arg1+ ",'" + arg2+ "');</script>");
更多:
从C#调用Javascript函数 [ ^ ]
这篇关于如何从C#代码访问javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文