Question

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"];
}
Was it helpful?

Solution

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 });

OTHER TIPS

You're trying to get a posted parameter from the query string rather than the form it was posted from.

Try:

context.Request.Form["CompanyName"];

Or just:

context.Request["CompanyName"]

As you are using a post, you should look in the Request.Forms collection instead of the QueryString.

Try

string ImeTvrtke = context.Request["CompanyName"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top