My function
<script type="text/javascript">
function methodtocall(id) {
// My code
}
</script>
My ashx page
public class sampleClass : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
// here i need to call that method
}
}
yes i referred net.But no solutions for that. mostly they give solution to call from method to ashx or call from ajax.
can anyone direct me with correct thing?
答案 0 :(得分:0)
Refer like this,
ClientScript.RegisterStartupScript(this.GetType(), "methodtocall", script, true);
as per code,
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);
}
}
Hope this helps..!
reference Link : Link
答案 1 :(得分:0)
你可以这样做
context.Response.Write("<script type='text/javascript'>function closeCurrentTab(){var conf=confirm('Are you sure, you want to close this tab?');if(conf==true){close();}}</script>");
context.Response.Write("<script type='text/javascript'>closeCurrentTab();</script>");