ASP.NET 2.0 ViewState Adapter And session

Posted: October 3, 2005 in Uncategorized

Craete a simple application put a datatgridview and load it with viewstate enabled.

code:-

 

protected

 

void Page_Load(object sender, EventArgs e){

if (!Page.IsPostBack)

{

string[] arr = newstring[1300];

for (int i = 0; i <= 1299; i++)

{

arr[i] =

“shreeman”;

}

GridView1.DataSource = arr;

GridView1.DataBind();

 

}

}

 
Now See the viewstate size get generated for each postback.
 
Now we ll create an adapetr and store the viewstate in Session .
 
 
 
 
Here is the adapter Code:-

using

System;using

System.Collections.Generic;using

System.Text;namespace

ClsDemoAdapter{

publicclassviewstateadapter : System.Web.UI.Adapters.PageAdapter

{

publicoverride System.Web.UI.PageStatePersister GetStatePersister()

{

returnnew System.Web.UI.SessionPageStatePersister(this.Page);

 

}

}

}

 

 

Now in the same application add a reference to the Above assembly ClsDemoadapter.viewstateadapter.

add a App_Broiwser Folder and add a Browser file Viewstateadapter.browser

and chnage the content of the browser as the following:-

 

<

browsers>

<browserrefID=Default>

<

controlAdapters>

<

adapter

controlType=System.Web.UI.Page

adapterType=ClsDemoAdapter.viewstateadapter

/>

</controlAdapters>

</

browser>

</browsers>

 

Now Runt he application and see the Viewstate by Right Click –>view Source and you are viewstate get stored in Session .

 

 also check out the interestign behavior

So what’s new in ASP.NET 2.0? There’s a new attribute in the <pages> section named maxPageStateFieldLength

<pages maxPageStateFieldLength=”5″ />

 

Read more here in dino’s blog here  http://weblogs.asp.net/despos/archive/2005/09/28/426137.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s