473,720 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: Questions about ViewState versus Session.

Sky
Although I've been using C# for the last month or so, and accepting out of
blind faith the ViewState, I do have some nagging questions about it... can
you help verify the following statements?

Application is across all sessions.
Session is across all pages.
ViewState is sort of like Session, but for only one page. <-- Correct
statement?

Session is stored between page requests, somewhere in mem or IIS files --
but can be rerouted to DB.
ViewState is sent to Client and returned on every post <-- Correct
statement?

If you load a DataSet.Table of 10 columns, 10 rows, and Bind it to a
DataGrid
you are sending to the Client 10x10 html cells of a table -- PLUS in the
ViewState 10x10 values encrypted. <--Correct statement?

If you load a DataSet.Table of 10 columns, 10 rows, and Bind it to a
DataGrid
but hide 7 columns you are sending to the Client 3x10 html cells of a
table -- PLUS in the ViewState 10x10 values encrypted. <--Correct statement?

Therefore, if you load a DataTable with 10 columns, 1000 rows, Bind it to a
DataGrid, but put Paging on 10 per page...
I am sending 10x10 html cells to the client -- PLUS 10x1000 cells in the
ViewState?????
If I DataBind a DataTable to a grid on page_load, I don't have to rebind it
again until I update the database, and have to repick up the new DataSet <-
Correct?
Any other comments you may have as to what it is, and "how to think of it"?

Thank you so much,
Sky


Nov 18 '05 #1
1 1707
Hi,

first off you might want to take a look at this article:

ViewState: All You Wanted To Know
http://aspalliance.com/135

Well,

-ViewState is page-specific
-By default ViewState is roundtripped to the client, but can also be stored
on custom stores like Session or database
-ViewState contains the values that aren't carried along with the request
normally, yes, helping with control persistence over postbacks (only the
values, not controls themselves)
-Yes, ViewState is kept even if control wouldn't be rendered (occasionally
hidden control can keep its state as long as it is along with the controls
collection between the subsequent requests by the same client)
-As far as I know, persisting the state (like with DataGrid) is all or
nothing. This is though a place for custom paging solution when you don't
need to bind that much records, but data store handles the paging not the
grid from all the data. E.g one page at a time is bound to the grid and
stored to ViewState (ViewState isn't for the paging in this case actually
but to keep the grid if some other controls causes a postback and grid isn't
databound on all request, as it shouldn't be)
-Yes, thanks to ViewState you need only to rebind the controls when logic
requires to.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


"Sky" <ne********@nos pam.xact-solutions.com> wrote in message
news:uu******** ******@tk2msftn gp13.phx.gbl...
Although I've been using C# for the last month or so, and accepting out of
blind faith the ViewState, I do have some nagging questions about it... can
you help verify the following statements?

Application is across all sessions.
Session is across all pages.
ViewState is sort of like Session, but for only one page. <-- Correct
statement?

Session is stored between page requests, somewhere in mem or IIS files --
but can be rerouted to DB.
ViewState is sent to Client and returned on every post <-- Correct
statement?

If you load a DataSet.Table of 10 columns, 10 rows, and Bind it to a
DataGrid
you are sending to the Client 10x10 html cells of a table -- PLUS in the
ViewState 10x10 values encrypted. <--Correct statement?

If you load a DataSet.Table of 10 columns, 10 rows, and Bind it to a
DataGrid
but hide 7 columns you are sending to the Client 3x10 html cells of a
table -- PLUS in the ViewState 10x10 values encrypted. <--Correct statement?

Therefore, if you load a DataTable with 10 columns, 1000 rows, Bind it to a
DataGrid, but put Paging on 10 per page...
I am sending 10x10 html cells to the client -- PLUS 10x1000 cells in the
ViewState?????
If I DataBind a DataTable to a grid on page_load, I don't have to rebind it
again until I update the database, and have to repick up the new DataSet <-
Correct?
Any other comments you may have as to what it is, and "how to think of it"?

Thank you so much,
Sky

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2275
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and disable the session state in Web.Config the VIEWSTATE variable is still maintained and stores some values. Can anyone tell what those values are for, i.e what other info is stored in VIEWSTATE other than the session ID and the control values ?
1
3751
by: Ralph Soons | last post by:
Hi all, I am trying to save the viewstate in a session instead of storing it in a hidden of the webpage which is default. This because of performance reasons. When I use line 2 in combination with line 4, my application works. Using Line 1 in combination with line 3 (and of course renaming httpSessionState1 to httpSessionState) results in the error as mentioned below. protected override object LoadPageStateFromPersistenceMedium() {
6
4344
by: clsmith66 | last post by:
Is it possible to store the same information about a control that would be saved in the ViewState in a Session state? I have a page with three treeview controls and if I enable the view state for the controls I get huge delays on postbacks, but if I disable the viewstate I lose all my information. Any sugesstions?
7
2042
by: et | last post by:
I'm not sure I understand the use of the ViewState. Do I understand correctly that values of controls are automatically held in a hidden control called ViewState? If so, then why can't we get them, or how do we get that value? I always have to set the ViewState("FirstName") = txtBox.text myself before a postback is done, otherwise, the value of ViewState("FirstName") is always empty; there doesn't seem to be a way to retrieve that...
3
2097
by: MattC | last post by:
With respect to Peter Bromberg's article ( http://www.eggheadcafe.com/articles/20040613.asp ) I wish to store my viewstate info in the Session object rather than the cache (as it is per user info). I have tried the following but am unable to serialize the viewstate?? protected override void SavePageStateToPersistenceMedium(object viewState) { string str = "VIEWSTATE_" + Request.UserHostAddress + "_" + DateTime.Now.Ticks.ToString();
3
4572
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and set textboxes, radio buttons, etc - that viewstate is fine. Then I have a linkbutton that does a Server.Transfer over to Page2.aspx. When I Server.Transfer back to Page1.aspx, the viewstate info is lost. I ran across another example of this last...
6
1597
by: mosscliffe | last post by:
I am testing for how/when a page is posted back and I decided to use a ViewState variable in PageLoad to set up a counter, but it appears, the ViewState is cleared on each PageLoad. So then I used SESSION and that worked. Am I correct in assuming ViewState is cleared on each PageLoad or is my code incorrect. VIEWSTATE If IsNothing(ViewState("PbCounter")) Then
3
1187
by: Trust Me; I'm from the government | last post by:
I have an employee class - in my page, when it loads, it gets all the employee data, including the employee Number. I have Dim emp As New Employee (at the top of the page, so it's global to the page) emp.empno=Datareader("empno") - and yes, it does get populated, correctly, at page Load Here's what I need, and isn't working: I have a button on that page, which does a Server.Transfer to another page, using that number, so I do something...
0
8727
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9365
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9126
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9055
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5972
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4482
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.