ClientScript不是类C#正常工作 [英] ClientScript not working properly on class C#
本文介绍了ClientScript不是类C#正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要部署到C#中的脚本,通常使用的方法,如:
I want to deploy a script on C# which usually uses methods like:
ClientScript.RegisterStartupScript(GetType(), "script", "Details('" + hdnId.Value + "');", true);
不过,我想使运行该code类:
However I wanted to make a class that runs that code:
public class WebUtilities
{
public static void CustomScript(Page objPage, string strScript)
{
objPage.ClientScript.RegisterStartupScript(objPage.GetType(), "script", strScript, true);
}
}
当我打电话WebUtilities.CustomScript,有时它的工作原理,但留下了//]]>在页面的底部。
When I call WebUtilities.CustomScript, sometimes it works, but leaves a //]]> at the bottom of the page.
和有一个场合,它并没有在所有的工作。我只注意到,第一种方法,和第二个不
And there is one occasion that it does not work at all. I only noticed that the first method works, and the second one doesn't.
我怎样才能让这个类的版本才能正常工作?
How can I make the class version to work properly?
推荐答案
我有这个功能,它始终工作,试试吧。
I have this function, and it always works, try it
public static void callJavascriptFunction(string strScript)
{
if (HttpContext.Current == null && HttpContext.Current.Handler is Page) { return; }
Page currentPage = (Page)HttpContext.Current.Handler;
ScriptManager.RegisterStartupScript(currentPage,
currentPage.GetType(),
"Funct",
strScript,
true);
}
这篇关于ClientScript不是类C#正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文