Solved

Can I store a class to a Page, like viewstate (for concurrently opened pages)?

Posted on 2008-06-19
5
198 Views
Last Modified: 2013-11-07
I have a web administration page that allows changing of website stuff like CSS styles, banners, images, page titles, etc. Currently, I store page inputs in a class, then into a session variable, just so the administrator can see the page before actually saving it to the file system. I'm running into a problem where the administrator has two admin pages opened in their browser and working on them concurrently, say tab1 and tab2. Since I'm storing the page inputs into a single session variable called (MyClass)Session["PageInputs"], the last opened page (tab2) overwrites tab1's page inputs in that session variable. You can imagine going back and forth from tab to tab can cause corruption and unintended data being saved to the wrong page with this methodology.

I'm trying to come up with a way where instead of storing the page inputs into a single session, each page has the page inputs stored. This way I can open multiple pages and work on them currently. Is there a way to store a class to the Page? I couldn't find a viewstate for the "Page" class. Maybe there's another way to store a class per opened page and work on them concurrently?
0
Comment
Question by:bemara57
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:ororiole
ID: 21827780
Why not just store them in the viewstate it self?
           MyClass myAdminClass = new MyClass();
            ViewState["spam"] = myAdminClass;

            var savedClass = (MyClass)ViewState["spam"];

and mark your class as serializable:
[Serializable()]
public class MyClass
{ ...
}
0
 

Author Comment

by:bemara57
ID: 21827922
The thing is that I make changes to that class thru App_Code methods. I can't get a hold of the ViewState from App_Code can I?
0
 
LVL 16

Expert Comment

by:ororiole
ID: 21828582
How where you storing them into the Session object? thru HttpContextUtility?
0
 

Author Comment

by:bemara57
ID: 21830706
Ya, thru HttpContext.Current.Session, but I don't see that Current has any ViewState in there.
0
 
LVL 16

Accepted Solution

by:
ororiole earned 500 total points
ID: 21850066
Well, there are a couple of ways to fix that. Somewhere you instantiate your appcode objects right? and somewhere you call the methods on those objects. Pass them the Page object in the constructor if that works or just when you call a method: appcodeObject.MyMethod(Page, blah, blah); Then you have access to the viewstate.


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now