c#: with a Handler(.ashx) get post send with javascript

11,710

When you make a POST request, the value is not sent as part of the query string. So don't look in the query string for it. Retrieve it like this:

string ImeTvrtke = context.Request["CompanyName"];

Alternatively if you wanted to be sent as part of the query string then use a GET request:

jQuery.get('/CartHandler.ashx', { 'CompanyName': CompanyName });
Share:
11,710
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I am trying to get a string from a textbox in a .aspx page. When I debug my site jQuery.post is able to see the input value, but when I try to get the value in my handler, he is giving me NULL back. Anyone help!!!

    JS:

    CompanyName = $("#company").val();
    jQuery.post('/CartHandler.ashx', { 'CompanyName': CompanyName });
    

    ASHX:

    public void ProcessRequest(HttpContext context)
    {
        string ImeTvrtke = context.Request.QueryString["CompanyName"];
    }
    
  • Admin
    Admin over 10 years
    I tryed with GET, it's the same.
  • Darin Dimitrov
    Darin Dimitrov over 10 years
    Hmm that's strange. Can you see the AJAX request being made in Fiddler?
  • Admin
    Admin over 10 years
    When I post with jquery serialize, I am able to get in the handler the whole form, but I need only one string
  • Darin Dimitrov
    Darin Dimitrov over 10 years
    This should work with only a single value. Maybe the code you have shown in your question is not the actual code.
  • dougajmcdonald
    dougajmcdonald over 10 years
    If you can't get the string, then your probably want the .Value of the Request[] / Request.Form[], apologies, I didn't understand that as your problem