简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM