ViewState

Discussion in 'ASP .Net' started by Jim Heavey, May 10, 2004.

  1. Jim Heavey

    Jim Heavey Guest

    If I want to save a class into a viewstate variable,what do I have to
    implement in order to do this?

    Thanks in advance for your assistance!!!!!!!!
    Jim Heavey, May 10, 2004
    #1
    1. Advertising

  2. Jim Heavey

    Janaka Guest

    Make sure to properly cast your class back when your reading it and check it
    exists. For example,

    Set the class:
    ViewState["SavedClass"] = myClass;

    Read the class:
    MyClass saved = (MyClass)ViewState["SavedClass"];
    if (saved != null)
    {
    // Do something
    }


    "Jim Heavey" <> wrote in message
    news:Xns94E53FF0ED66BJimHeaveyhotmailcom@207.46.248.16...
    > If I want to save a class into a viewstate variable,what do I have to
    > implement in order to do this?
    >
    > Thanks in advance for your assistance!!!!!!!!
    Janaka, May 10, 2004
    #2
    1. Advertising

  3. Jim Heavey

    Jim Heavey Guest

    Thanks, But I was wondering about the "class" istself. I can not save an
    ordinary class to a viewstate. That class has to implement some interface
    inorder to be serializable. I can't remember the interface that I have to
    implement.
    Jim Heavey, May 10, 2004
    #3
  4. Hi, Ji

    You will need to implement ISerializable
    VB
    <Serializable()> Public Class MyClass
    Implements ISerializable
    C#
    [Serializable()]
    public class MyClass1: ISerializable

    Bin Song, MC
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, May 10, 2004
    #4
  5. To save any object into ViewState, it must be serializable. Why do you want
    to save a class in ViewState?

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Jim Heavey" <> wrote in message
    news:Xns94E53FF0ED66BJimHeaveyhotmailcom@207.46.248.16...
    > If I want to save a class into a viewstate variable,what do I have to
    > implement in order to do this?
    >
    > Thanks in advance for your assistance!!!!!!!!
    Kevin Spencer, May 10, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Rush
    Replies:
    2
    Views:
    521
    Ben Rush
    Dec 5, 2003
  2. Steph
    Replies:
    2
    Views:
    1,660
    heislord5
    May 11, 2011
  3. ujjc001
    Replies:
    0
    Views:
    1,370
    ujjc001
    Jul 27, 2005
  4. sck10
    Replies:
    6
    Views:
    912
    sck10
    Sep 1, 2006
  5. mark

    Viewstate errors... how do I get viewstate working?

    mark, Feb 20, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    275
Loading...

Share This Page