Suave Nti
Suave Nti

Reputation: 3739

Pass Object from one Aspx to another from Javascript

Correct me if I am doing wrong.

I have a Login page which uses a Webservice to process login. In my Login page I use Jquery with JSon to consume the webservice.

After the login is processed I recieve an object and I want to redirect the recieved object to home page.

Let me know how.

Thanks Samuel

Upvotes: 2

Views: 607

Answers (2)

Abdul Munim
Abdul Munim

Reputation: 19217

POST redirect the received JSON to server, and deserialize the JSON to your typed object. You can consider keeping the object in your SESSION and access it when required.

UPDATE

put a hidden field in your aspx/ascx page

Once you receive your JSON Data from your service. Just put your response to the hidden field. (USE JQUERY)

$("input[id$=jsonResponse]").val(responseFromService);

On your Page_Load method on your home.aspx

Use JavaScriptSerializer to deserialize your JSON data

JavaScriptSerializer serializer = new JavaScriptSerializer();

LoginData loginDataObject = serializer.Deserialize<LoginData>(jsonResponse.Value);

Now you can consider putting your loginDataObject to SESSION and access through out your application scope

// to store in session
Request.Session["loginData"] = loginDataObject;
// to retrieve from session
LoginData loginDataObject = (LoginData) Request.Session["loginData"];

Upvotes: 1

Neil Thompson
Neil Thompson

Reputation: 6425

You could store the object in a cookie and change the url with location.href or something similar?

Upvotes: 0

Related Questions