Bhupendra Shukla
Bhupendra Shukla

Reputation: 3914

How to modify the session variable inside the asp.net webmethod

I have following webmethod where i want to modify the value of the existing Session variable but here inside the webmethod whenever i assign the value to that session variable, the value is not assigning to it.

WEBMETHOD

 [WebMethod(EnableSession = true)]
    public static List<tblCustomerList> CustData(String id)
    {
        Int32 count=(Int32) HttpContext.Current.Session["pgnum"];
        HttpContext.Current.Session["pgnum"] = count++;
        DataGridEntities _dbContext = new DataGridEntities();
        var filteredResult = _dbContext.tblCustomerLists.ToList();
        return filteredResult;
    }

Upvotes: 3

Views: 1857

Answers (1)

Devesh
Devesh

Reputation: 4550

In your code you should do like this, because count++ will assign the existing value and then increment its value

          HttpContext.Current.Session["pgnum"] = ++count;      

Upvotes: 5

Related Questions