开发者

Where to store currently selected item id?

开发者 https://www.devze.com 2023-02-16 18:47 出处:网络
I\'m trying to write an asp.net app which searches a sql db and returns/updates the data. I want to be able to hold the currently selected id of the item my user has selected. For example a doctors s

I'm trying to write an asp.net app which searches a sql db and returns/updates the data.

I want to be able to hold the currently selected id of the item my user has selected. For example a doctors surgery would select a patient record then be able to browse the app without having to re-select that patient on each page.

What would be the best way to do this. Ideally I need to be able开发者_如何学运维 to get this ID application wide. the only thing i can think of is to create a public class, store the id and make it public but this seems quite messy

Thank you


Store it in a Cookie or a Session variable.

Cookie info http://msdn.microsoft.com/en-us/library/ms178194.aspx

Session Info http://msdn.microsoft.com/en-us/library/ms972429.aspx


I would recommend storing it in a session variable:

Page.Session["CurrentPatient"] = YourPatient record

To get the record you would use:

YourPatientRecord = Page.Session["CurrentPatient"] as PatientRecord;

To make things easier I usually create a property in the page or base page to use throughout the system.

eg:

protected PatientRecord CurrentPatient
{
  get
  {
    return Session["CurrentPatient"] as PatientRecord;
  }
  set
  {
    Session["CurrentPatient"] = value;
  }
}

Then to use it in the page it would simply be:

PatientRecord oPatientRecord = this.CurrentPatient;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号