0

I am two page and i need to pass certain data as json object to other page.

Page1.aspx Code

obj.Name= "My Name";
obj.Age= 30;
obj.Country= "Japan";
.....
.....
string json = JsonConvert.SerializeObject(obj);

Response.redirect("Page2.aspx");

Page2.aspx

How can i pass this information to page2.aspx when i do a redirect.

One way i can do it to pass it as form object in one of the hidden fields and then deserialize it.

I was wondering if there is another easy way.

Learning
  • 19,469
  • 39
  • 180
  • 373

2 Answers2

0

How about

Response.redirect("Page2.aspx?MyJson=json");

And in "Page2.aspx" read the values:

string FromJson = Response.QueryString["MyJson"].ToString();
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • I am concern about the length of the object. For now i am passing as a hiddenfield – Learning Jan 11 '17 at 06:32
  • @Learning You can have a look at [pass values across the pages in ASP.net](http://stackoverflow.com/a/14956219/3796048) – Mohit S Jan 11 '17 at 06:35
  • if the json size in big you can save the json file on disk and retrieve it on another page. and can pass the name of the file in the `redirect` – Mohit S Jan 11 '17 at 06:37
0

For this you can use a session variable.

obj.Name= "My Name";
obj.Age= 30;
obj.Country= "Japan";
.....
.....
string json = JsonConvert.SerializeObject(obj);

Session["json"] = json;

Response.redirect("Page2.aspx");

Then get values using session on your page2.aspx

Thili77
  • 1,061
  • 12
  • 20