Deserializing custom ArrayList type from ViewState... help..

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: Deserializing custom ArrayList type from ViewState... help..

    > // this doesn't work
    > EmployeeList ml (EmployeeList)ViewState["test"];
    try:
    ViewState["test"] = ml;

    make sure the classes that are stored in the arraylist are attributed w/
    [Serializable] as well.


    "Ramzey" <jeremy_deats@hotmail.com> wrote in message
    news:d393d1b1.0306241208.38d78c85@posting.google.c om...
    > I have a custom class that uses ArrayList as its base type. I've
    > tagged on the [Serializable] attribute to the class definition and I
    > can add the class to ViewState or Session on my ASP.NET page.
    >
    > // this works fine
    > EmployeeList myemp = new EmployeeList();
    > myemp.Add(emp1);
    > myemp.Add(emp2);
    > ...
    >
    > ViewState["test"] = myemp;
    >
    >
    > The problem comes when trying to cast my custom collection out of
    > ViewState. The failure occurs when I try to cast it out, however if I
    > try to cast back to ArrayList that works fine.
    >
    > e.g.
    >
    > // this works
    > ArrayList ml = (ArrayList)ViewState["test"];
    >
    > // this doesn't work
    > EmployeeList ml (EmployeeList)ViewState["test"];
    >
    > What do I need to add inside my custom collection object to make it so
    > that ViewState can cast back to it when deserialization occurs?

    PJ Guest

  2. Similar Questions and Discussions

    1. viewstate and custom control
      I have custom control with dropdownlist. I am using this custom control in a repeater. After the post-back the control properties that i stored in...
    2. Custom control viewstate (?) issue!
      I've been struggling for a day and yet haven't found a solution to such a problem: I have, let's say, an apsx page, which contains a UserControl,...
    3. Losing viewstate in custom control
      I have a custom control I derived from the datagrid control and set a couple of values in viewstate("foo") = "bar" but on postback they are...
    4. Visual Studio.NET 2003 generates type object[] for ArrayList method return
      I've noticed what appears to be a bug in the Visual Studio.NET (1.0 and 2003 versions). If I declare a web method like so: public ArrayList...
    5. Missing Viewstate in Custom Control
      Easy one for gurus:::: Could someone tell me why this custom control bombs during postback? To duplicate: compile this control, put it in your...
  3. #2

    Default Re: Deserializing custom ArrayList type from ViewState... help..

    All classes down the chain are tagged [Serializable]. If this were a
    problem I wouldn't be able to cast back to an ArrayList type either,
    but since I can it seems I have something missing from my EmployeeList
    class. It seems during the deserialization process the deserializer
    wants to cast it back to an ArrayList type. I assume deserializer
    method call from ViewState is getting a response back from my custom
    object that it should be cast to an ArrayList type.. The Microsoft
    documention makes sense, but it doesn't address this.
    Ramzey Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139