0

The project continues . .

I have a form that I'm serializing with the jquery form plugin. Works great.

I am then using the jquery ajax feature to post to an asp.net web method so that each form element can be inserted into a database.

My issue is this, how do I loop through each of the request.form params that is sent via ajax in the asp.net web method. If I use a standard Request.Form("") I receive an error. Here is my code.

var queryString = $('input').fieldSerialize(); 

$.ajax({
   type: "POST",
   url: "Detail.aspx/doPostTest",
   data: "{ 'txtQuery': '" + queryString + "'}",
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   success: function (data) {
        var products = eval(data.d);                             
        console.log(products);
   }
});

Code behind

<System.Web.Services.WebMethod()> _
Public Shared Function doPostTest(ByVal txtQuery As String) As String

    'Grab Request Form variables
    Request.Form("txtMember")
End Function

The error I receive on the server side is the following:

Cannot refer to an instance member of a class from within a shared method or shared member . . etc.

Thanks in advance.

1 Answer 1

2

You will need to call HttpContext.Current.Request to access your current HttpRequest from static methods.

The Page class your page inherits from contains an instance property Request; therefore it's not possible to access this prop from your static methods.

Sign up to request clarification or add additional context in comments.

Comments

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.