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 ?

2
  • That string is already encoded.. you need to Decode it. Commented Dec 3, 2013 at 7:37
  • @Dan-o used decode it works but not able to store value in variable. Commented Dec 3, 2013 at 7:44

1 Answer 1

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
  }
Sign up to request clarification or add additional context in comments.

4 Comments

this method will initiate auto. when this call ajaxExecute.aspx?Fn=CAO2 is made ?
You have to change it to call ajaxExecute.aspx/DoFoo
Done this but it coudnt able to hit break point on static method. It a Web Application ASP.NET & C#. Not a Web Service !! Will it Still Work ?
Yes you can add them directly to the ajaxExecute.aspx.cs file stackoverflow.com/questions/10688951/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.