I have assigned session a custom class's object like:
Services Obj = getServiceDetails(3); //getting all data of Service where Id = 3
Session["ServiceObj"] = Obj;
Now I want to assign its value to same class's another object in a model class. I don't know how to do it.
I tried but it is not valid way.:
Services oldObj = <Services>Session["ServiceObj"];
Pls Help me. I don't know how to do it.
Session is a variable on the backend server side, while JS is a previous script. There is no ready-made method in JS to get the value of Session, and it needs to be obtained through the server language. For example, java can be used to get the value of Session and assign it to JS variable.
The Session Storage basically consists of 4 main methods. setItem(key, value): This method is used to set the value into the Session Storage based on the key. getItem(key): This method is used to get the value that is stored into the Session Storage. It takes a key and returns the value.
Correct type cast requires round brackets:
Services oldObj = (Services)Session["ServiceObj"];
you should use Services oldObj = (Services)Session["ServiceObj"];
instead of Services oldObj = <Services>Session["ServiceObj"];
not <Services> use (Services) for casting
Cast it with your Class like this
Services obj = (Services)Session["ServiceObj"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With