如何从ashx处理程序文件中调用javascript函数

问题描述 投票:0回答:1

我的功能

<script type="text/javascript">
function methodtocall(id) {
  // My code
}
</script>

我的ashx页面

public class sampleClass : IHttpHandler {

public void ProcessRequest (HttpContext context) {

    context.Response.ContentType = "text/plain";
// here i need to call that method
}
}

是的,我提到了net.But没有解决方案。他们主要提供从方法调用到ashx或从ajax调用的解决方案。

谁能用正确的东西指引我?

javascript c# ashx
1个回答
0
投票

像这样指,

ClientScript.RegisterStartupScript(this.GetType(), "methodtocall", script, true);

按照代码,

public class sampleClass : IHttpHandler {

public void ProcessRequest (HttpContext context) {

context.Response.ContentType = "text/plain";
var id = "someid"; //implement the id that you want to pass to the Javascript function
ClientScript.RegisterStartupScript(this.GetType(), "methodtocall", id, true);
}
}

希望这可以帮助..!

参考链接:Link

© www.soinside.com 2019 - 2024. All rights reserved.