Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-19
5
Medium Priority
?
212 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

886 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