1

i am performing ajax call on my .aspx page

Passing some values which contain characters like '/' , '&' , '-' , '.' hence using encodeURIComponent

$('#divDialog').html('<p>Loading Please wait...</p>').dialog({ title: 'Processing Information', modal: true, resizable: false, draggable: false }).load('ajaxExecute.aspx?Fn=CAO2',
    {
        'EmploymentType': encodeURIComponent($('#cmbEmploymentType').val()), 'NatureIncome': encodeURIComponent($('#cmbIncomeNature').val())
    },
    function (response, status, xhr) {
        $('#divDialog').dialog('close');
        // Some Code
}
});

i am trying to get those values in c#

if (Request.Form["EmploymentType"] != "" && Request.Form["EmploymentType"] != null) string sEmpType = Convert.ToString(Request.Form["EmploymentType"]);

QuickWatch Shows values in Convert.ToString(Request.Form["EmploymentType"])

As Car%2FTruck%2FBoat%2FPlane%20Dealer

I tried HttpUtility.UrlEncode(Convert.ToString(Request.Form["EmploymentType"])) But Same result

How can i get string Car/Truck/Boat/Plane Dealer As it is in variable ?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Shaggy
  • 5,422
  • 28
  • 98
  • 163

1 Answers1

1

You are using Request.Form, this will only work for from submits, not for ajax requests. Have a look at C# WebMethods they will turn the request data into C# objects for you. heres an example project

in ajaxExecute.aspx.cs:

 [WebMethod]
 public static void DoFoo(String EmploymentType, String NatureIncome){
     string sEmpType = EmploymentType;
 }

Javascript:

 $(...).load('ajaxExecute.aspx/DoFoo',
     {
        'EmploymentType' : $('#cmbEmploymentType').val(),
        'NatureIncome':  $('#cmbIncomeNature').val()
     }
     // rest of arguments
  }
actual_kangaroo
  • 5,971
  • 2
  • 31
  • 45