Search code examples
asp.netsessionwebmethod

session modify from webmethod


is it possible to modify a session from a webmethod, well the complete description is,

I have a button that client side triggered to add data from textboxes into one new row inside a session

The session declared as

public List<Some_Business_Object_Here> A_Session
{
            get
            {
                return (List<Some_Business_Object_Here>)Session["Session_Name_Here"];
            }
            set
            {
                Session["Session_Name_Here"] = value;
            }
}

and The WebMethod

[WebMethod]
public static string InsertItemDt(List<string> dataIns)
{
            BOResponse objRes = new BOResponse();
            SomeFormHere form = new SomeFormHere();

            Some_Business_Object_Here objDet = new Some_Business_Object_Here();
            objDet.Data1 = dataIns[0];
            objDet.Data2 = Convert.ToInt32(dataIns[1]);
            objDet.Data3 = Convert.ToDecimal(dataIns[2]);            

            objRes = form.A_Processing_Method(objDet, ListItemDetail);

            return new JavaScriptSerializer().Serialize(objRes);
}

and if the method processing to add a new row after some validation

is it possible to do it with this kind of method?

Edit: BOResponse is object for validation, containing only error code and catch error message

so the method be like

 Private BOResponse A_Processing_Method (Some_Business_Object_Here obj)
{
    try
    {
       (Some Validation Here...)

       if (!validation)
       {
          MsgCode = 10;
          MsgDesc = "Some Custom Error Text Here"
       }
       else
       {
           A_Session.Add(obj);
       }
    }
    catch (Exception err)
    {
       MsgCode = 20;
       MsgDesc = err.Message;
    }
}

Solution

  • nevermind, seems it's working this way