0
 string ID = context.Request.QueryString["BudgetId"] == null ? null : context.Request.QueryString["BudgetId"].ToString();
            context.Response.ContentType = "text/Plain";
            string Budgetid = context.Request["ID"];
            string Country = context.Request["ddlcountry"];
            string State = context.Request["ddlstate"];
            string City = context.Request["ddlcity"];
            string Location = context.Request["txtlocation"];

Above Iam Taking all the Control IDS which is coming from ASPX page but ID is Coming from ASPX page how to pass Country, state,city values here in genric handler

Ahmad
  • 1
  • 4
  • how to pass query string? put code – Genish Parvadia Dec 04 '15 at 06:29
  • Here All the control Values should come from aspx ,like I have selected countryID respective state city should go to genric handler with the help of budgetID – Ahmad Dec 04 '15 at 06:31
  • At this point you cannot because the registered handlers have finished processing. – Huske Dec 04 '15 at 06:33
  • Any other Alternative to Pass this Control selected values to handlers – Ahmad Dec 04 '15 at 06:36
  • Please see my answer. You need to register your handler in the handlers section of the web config and then process the request through Context in the handler. – Huske Dec 04 '15 at 07:03

2 Answers2

0

Handlers respond to a request being made. You might want to check the context inside of your handler and not on the page. That way you don't have to process the above in the ASPX page. Once completed you could add some value to a session to indicate that you processed the request.

Huske
  • 9,186
  • 2
  • 36
  • 53
0

Here's my sample implementation of ASP.NET connecting to a Generic Handler.

my WebForm1.aspx.cs code

public partial class WebForm1 : System.Web.UI.Page
    {
        public string myCurrentUser = "MyUser";
        public string myCurrentUserID = "1";

        protected void Page_Load(object sender, EventArgs e)
        {

        }

    }

Sample ASP.NET page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

<!--note that you need to have an updated jquery version here..-->
<script src="jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function () {
        var PassValues = "?User=" + "<%=myCurrentUser%>" + "&ID=" + "<%=myCurrentUserID%>"
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "Handler1.ashx" + PassValues,
            success: function (data) {
                alert(data);
            },
            error: function (err) {
                var str = err;
            }
        });
    });

</script>

NOTE: Ensure that the $.AJAX URL PATH of the Handler is correct

enter image description here

my Handler1.ashx.cs code

public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello User <" + context.Request.Params["User"] + "> with ID <" + context.Request.Params["ID"] + ">");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
ken lacoste
  • 894
  • 8
  • 22