Moslem7026
Moslem7026

Reputation: 3338

pass object (Not Value) in asp.net WebForm

In ASP.Net MVC passing the object and model is safe and easy to implement, and passing value via QueryString in webform is simple too.

What is the best way to pass objects to another page?

Upvotes: 1

Views: 1370

Answers (1)

Kinjo
Kinjo

Reputation: 1456

The object you want to pass can be saved in a session or the cache and then retrieved from some other page.

  1. Page 1: Save object to session with an identifier using the code: Session["SomeIdentifier"] = myObjectInstance;
  2. Move to Page 2
  3. Page 2: Retrieve object from session using the identifier using the code: var myObjectInstance = (MyObjectInstance) Session["SomeIdentifier"];

Or you can replace Session (which is persistent) by using Context.Items["MyObjectInstance"] (removed after a request), see my comment for the difference between the two.

Upvotes: 2

Related Questions