Tuesday, 15 December 2015

Handler

 function test() {
            alert("ss");
            var pID = $("#t").val();
            var tID = $("#t1").val();


            var urlToHandler = "Handler.ashx";

            $.ajax({
                type: "POST",
                url: urlToHandler,
                data: { a: pID, b: tID },
                dataType: "json",
                success: function (msg) {
                     alert(msg);
                    $("#t3").val(msg);
                }
            });
            alert("sss");
        }
 <input id="Button1" type="button" value="button" onclick="test();" />
  handler code for design:
using System;
using System.Web;

public class Handler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
         context.Response.ContentType = "text/plain";
         string a = context.Request.Params["a"].ToString();
         string b = context.Request.Params["b"].ToString();
        context.Response.Write(add(a,b));
    }

    public string add(string a, string b)
    {
        int c = Convert.ToInt32(a) + Convert.ToInt32(b);
        return c.ToString();
    }
    public bool IsReusable {
        get {
            return false;
        }
    }

}

No comments:

Post a Comment