a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewS

Discussion in 'ASP .Net' started by leal ting, Dec 29, 2003.

  1. leal ting

    leal ting Guest

    a class inherited from ArrayList,
    is saved to ViewState,
    why the type of the object read from ViewSate is not the class,
    but the parent, ArrayList
    [my email address ]


    the class inherited from ArrayList

    public class Fields: ArrayList
    {
    public Fields()
    {}
    }


    Save to ViewState
    this.ViewSate["FieldList"] = colFields;

    when reading, it raises an error,
    Fields colFields = (Fields)this.ViewSate["FieldList"]


    the right type
    ArrayList colFields = (ArrayLiist) this.ViewState["FieldList"];

    why? how to solve it? and how to read it directly?
    leal ting, Dec 29, 2003
    #1
    1. Advertising

  2. I have the same issue, but in VB.Net. In my attempts to solve it, I modified
    the class as follows, but that didn't change the behavior:

    <Serializable()> public class Fields
    inherits ArrayList
    implements ISerializable

    private sString as String
    private nInt as Int

    public sub New()
    end sub

    public sub New( byval info as Serializationinfo, byval c as
    streamingcontext)
    ' get variables from info
    end sub

    sub getobjectdata(byval info as Serializationinfo, byval c as
    streamingcontext) implements Iserializable
    'save variables to Info
    end sub
    end class

    "leal ting" <> wrote in message
    news:...
    > a class inherited from ArrayList,
    > is saved to ViewState,
    > why the type of the object read from ViewSate is not the class,
    > but the parent, ArrayList
    > [my email address ]
    >
    >
    > the class inherited from ArrayList
    >
    > public class Fields: ArrayList
    > {
    > public Fields()
    > {}
    > }
    >
    >
    > Save to ViewState
    > this.ViewSate["FieldList"] = colFields;
    >
    > when reading, it raises an error,
    > Fields colFields = (Fields)this.ViewSate["FieldList"]
    >
    >
    > the right type
    > ArrayList colFields = (ArrayLiist) this.ViewState["FieldList"];
    >
    > why? how to solve it? and how to read it directly?
    >
    >
    >
    >
    Bryan Donaldson, Feb 10, 2004
    #2
    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. PJ
    Replies:
    1
    Views:
    1,796
    Ramzey
    Jun 25, 2003
  2. pluck
    Replies:
    1
    Views:
    1,200
    Chris Riesbeck
    Jun 28, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,803
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    0
    Views:
    154
  5. 7stud --
    Replies:
    11
    Views:
    394
    7stud --
    Nov 9, 2007
Loading...

Share This Page