Solved

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

Posted on 2008-06-19
5
199 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

920 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

16 Experts available now in Live!

Get 1:1 Help Now