且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将c#函数返回值作为参数传递给Javascript

更新时间:2023-09-06 18:50:46

public static void calculate(string par)
      {
          // Cleans the message to allow single quotation marks
          string cleanMessage = par.Replace("'", "\\'");
          string script = string.Format("<script type=\"text/javascript\">


(document).ready(function() {JA('{0}');});< / script>,cleanMessage);

// 获取正在执行的网页
Page page = HttpContext.Current.CurrentHandler as Page;
// 检查处理程序是否为Page并且脚本未在页面上全部准备
if (page!= null &&!page.ClientScript.IsClientScriptBlockRegistered ( JA))
{
page.ClientScript.RegisterClientScriptBlock( typeof (< your class = name = > ), JA,脚本);
}
} < / 您的 >
(document).ready(function(){JA('{0}');});</script>", cleanMessage); // Gets the executing web page Page page = HttpContext.Current.CurrentHandler as Page; // Checks if the handler is a Page and that the script isn't allready on the Page if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("JA")) { page.ClientScript.RegisterClientScriptBlock(typeof(<your class="" name="">), "JA", script); } }</your>


您可以使用ajax jquery



You can using ajax jquery

function JA(location)
{