Users can define their own data types. Classes and structure definitions fall under user defined data types. If we want to play with user defined datatypes and ViewState, then really we need to concentrate on defining them.
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CodeProject
{
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
UserClass UC=new UserClass();
this.ViewState["Key"]=UC;
Response.Write("View State is workng..");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
public class UserClass
{
public UserClass()
{
_number=1;
_name="cp.com";
}
private int _number;
private string _name;
}
}
Bookmarks