Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2008-06-19
5
202 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 our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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