Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Saving list<> across postbacks
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
tshad  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 16:46
Newsgroups: microsoft.public.dotnet.framework.aspnet
From: "tshad" <t...@dslextreme.com>
Date: Fri, 6 Nov 2009 08:46:08 -0800
Local: Fri 6 Nov 2009 16:46
Subject: Saving list<> across postbacks
I have a page that is using a List collection (list<>) and I want to save it
across postbacks.

I tried adding it to my ViewState but get an error:

Type 'AutoUPS.ClientList' in Assembly 'AutoUPS, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' is not marked as serializable.

How do I set this up so I can save it?

In my web page I am doing:

     public partial class AutoUPS : System.Web.UI.Page
    {
       private int exceptionDrop;
        public static ClientList clientList = new ClientList();

     ...

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
            }
            else
            {
                clientList = (ClientList)ViewState["ClientList"];
            }
        }

        protected override void OnPreRender(EventArgs e)
        {

            base.OnPreRender(e);
            ViewState["ClientList"] = clientList;
        }

I am calling this from another page so I have my ClientList set as a static
and then want to save it so I don't have to call the database all the time.

Not sure if this is the best way but it seemed so.

Thanks,

Tom


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Göran Andersson  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 17:21
Newsgroups: microsoft.public.dotnet.framework.aspnet
From: Göran Andersson <gu...@guffa.com>
Date: Fri, 06 Nov 2009 18:21:05 +0100
Local: Fri 6 Nov 2009 17:21
Subject: Re: Saving list<> across postbacks

To make the class serializable, you add the [Serializable()] attribute
to it. It also requires the class to have properties that are both
readable and writable, and the class needs a parameterless constructor
so that the deserializing can recreate an instance.

However, putting the list in ViewState means that you are sending the
serialized data to the browser and back, which makes it slower to load
and postback.

You could save the list in a Session variable, then it would not be sent
to the client. Consider the memory usage though, if you use too much
memory for each session that limits the number of session that the site
can handle. You may want the limitation to be how many requests the
server can handle per second rather than an absolute limit on the number
of visitors.

--
Göran Andersson
_____
http://www.guffa.com


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tshad  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 18:22
Newsgroups: microsoft.public.dotnet.framework.aspnet
From: "tshad" <t...@pdsa.com>
Date: Fri, 6 Nov 2009 10:22:15 -0800
Local: Fri 6 Nov 2009 18:22
Subject: Re: Saving list<> across postbacks

"Göran Andersson" <gu...@guffa.com> wrote in message

news:uOo0DWwXKHA.4688@TK2MSFTNGP06.phx.gbl...

All the fields (3) are int or string.

> However, putting the list in ViewState means that you are sending the
> serialized data to the browser and back, which makes it slower to load and
> postback.

I realize that, but I have a dropdown that has client names and clientIDs.
The problem is that I also need the account  number to find a selection in
the dropdown (but only 2 values can be kept in a dropdown unless you
concatenate them but then you have another issue to deal with.

I just build a list<> with both the ID and Account# and if they put an
Account# (which is what they know) and then get the ClientID from the List<>
based on this Account# - I can then select the client in the dropdown.  But
to do that I would need to keep the List<> around somewhere.  It wouldn't be
very large.

> You could save the list in a Session variable, then it would not be sent
> to the client. Consider the memory usage though, if you use too much
> memory for each session that limits the number of session that the site
> can handle. You may want the limitation to be how many requests the server
> can handle per second rather than an absolute limit on the number of
> visitors.

Also, you have a time problem if they keep the page open (this is an office
app) but don't do anything.  You would lose the sesssion info.

Also, whether you keep the session on the page or in sessions, you still
need to pass the data around, right?

Thanks,

Tom


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google