Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Store ISeriable Object in ViewState ?

Store ISeriable Object in ViewState ?

Scheduled Pinned Locked Moved ASP.NET
xmlhelpquestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sandilian
    wrote on last edited by
    #1

    I want to store Custom Class object to ViewState for later use Note : I want to use ISeriable interface not [Serializable] property (When i use [Serializable] property, it is working fine but in my case i have to use only ISeriable Interface, I have option to store object into ViewState only not XML or File) PlZ help me. Sample.aspx Person oPerson = new Person(); oPerson.FirstName = "Sandilian"; oPerson.LastName = "Arumugam"; ViewState["Object"] = oPerson; Person cls1 = (Person)ViewState["Object"]; Response.Write(cls1.FirstName + " " + cls1.LastName); Person.CS //[Serializable] public class Person : ISerializable { private string _FirstName; private string _LastName; public string FirstName { get { return _FirstName; } set { _FirstName = value; } } public string LastName { get { return _LastName; } set { _LastName = value; } } public Person() { } public Person(string FirstName, string LastName) { this.FirstName = FirstName; this.LastName = LastName; } public void GetObjectData(SerializationInfo oInfo, StreamingContext oContext) { oInfo.AddValue("FirstName", this.FirstName); oInfo.AddValue("LastName", this.LastName); oInfo.SetType(typeof(Person)); } }

    P 1 Reply Last reply
    0
    • S Sandilian

      I want to store Custom Class object to ViewState for later use Note : I want to use ISeriable interface not [Serializable] property (When i use [Serializable] property, it is working fine but in my case i have to use only ISeriable Interface, I have option to store object into ViewState only not XML or File) PlZ help me. Sample.aspx Person oPerson = new Person(); oPerson.FirstName = "Sandilian"; oPerson.LastName = "Arumugam"; ViewState["Object"] = oPerson; Person cls1 = (Person)ViewState["Object"]; Response.Write(cls1.FirstName + " " + cls1.LastName); Person.CS //[Serializable] public class Person : ISerializable { private string _FirstName; private string _LastName; public string FirstName { get { return _FirstName; } set { _FirstName = value; } } public string LastName { get { return _LastName; } set { _LastName = value; } } public Person() { } public Person(string FirstName, string LastName) { this.FirstName = FirstName; this.LastName = LastName; } public void GetObjectData(SerializationInfo oInfo, StreamingContext oContext) { oInfo.AddValue("FirstName", this.FirstName); oInfo.AddValue("LastName", this.LastName); oInfo.SetType(typeof(Person)); } }

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      If you want to store it in directly ViewState, it must have the [Serializable] attribute. No other way. What is the problem with using the attribute?

      S 1 Reply Last reply
      0
      • P Paddy Boyd

        If you want to store it in directly ViewState, it must have the [Serializable] attribute. No other way. What is the problem with using the attribute?

        S Offline
        S Offline
        Sandilian
        wrote on last edited by
        #3

        PL do not accept this type of declaration. that is the problem . Can you suggest me some way to solve this problem.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups