I'm using an usercontrol (*.ascx) in a CMS system C#.NET
I've got a Gridview which displays address. You hav a link on the line items and you can click on the items (link) which navigates to other page with querystring info and displays the detail information. When the user clicks on cancel/back it returns the the overview page. Both are separate programs.
When the user clicks on Next, Next, Next e.g. page 7 is displayed. So clicking on an "adres link" on Page 7 will open a new page and when the user comes back it should display page 7 back again.
I was keeping the page numbers in a session. so when the user comes back it reads the pagenumber from the session. This works fine. But the issue is this module is used other placess too, and also in other portals (which uses the same module)
So when have clicked next next etc and you are on page 7 and then you open another portal or other Porgram which have the same module, it displays page 7. Because it reads the Session variable and sometiems it gives a dump because page 7 doesn't exist, because no much records.
Viewstate fix this issue, but everytime after clicking the adres item and coming back it displays page 1, which is not what I want.
As I said, I use the same开发者_如何学编程 module in other pages and other portals (same program with different settings CMS -system)... So where and how do I need to store the pagenumbers so it doesn't have conflict with other pages and other portals?
ViewState["page"] = 7 -> starts on page 1 always when you come back
Session["page"] = 7 -> page number is shared....
Why don't you keep a Structure or Dictionary instead of simple int in the session. In this you can store Page as well as the Module.
I believe you need to think about instantiation. It seems that you need to isolate each instance of your CMS so each one will share its own set of server variables, includinig session ones.
Well, it's true you're using some ASCX control, but you can have some "application identifier" so any of control instances can have their own set of values.
Anyway, storing long objects in session is a bad practice, since other modes than "in process" will serialize objects and deserialize them whenever you access to session's state.
Maybe you need some kind of custom session management in order to optimize performance and memory usage so your components will be rightly isolated and they will remain performant.
精彩评论