473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Going nuts with Viewstate

Hi guys
Till now i thougt I understood ViewState but as I was trying write my
LoadViewState method i am sort of confused with what this ViewState is and
what is its use.
I have my LoadViewState method , i was curious to know wheres the state of
Various controls getting set on Post back. So I tried viewing the ViewState
but it doesnot show any controls and their values. I also had to implement
SaveViewstate to have my LoadViewState get called and again this was called
only when my page added some values to the ViewState in SaveViewState
method.
So the confussion is on postback how are the values for each control get set
back to the values which i have set earlier.
protected override void OnLoad( EventArgs e ){

// Put user code to initialize the page here

if(!IsPostBack)

{

TextBox1.Text = "wEQ";

}

}

Here I am checking for IsPostBack so I am not setting them again. I thought
this cam for ViewState but cant see these there.

Or am i completely wrong here and ViewState doesnot do all this?

Thanks

Sourabh
Nov 18 '05 #1
2 1019
Hi,

about ViewState:
http://aspalliance.com/135

You seemed to work with TextBox. It has bit different workings with
ViewState because it also posts its value withn the form. I've discussed
about this in my blog post:
http://blogs.aspadvice.com/joteke/ar...03/15/767.aspx

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"sourabh" <so************@induslogic.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi guys
Till now i thougt I understood ViewState but as I was trying write my
LoadViewState method i am sort of confused with what this ViewState is and
what is its use.
I have my LoadViewState method , i was curious to know wheres the state of
Various controls getting set on Post back. So I tried viewing the ViewState but it doesnot show any controls and their values. I also had to implement
SaveViewstate to have my LoadViewState get called and again this was called only when my page added some values to the ViewState in SaveViewState
method.
So the confussion is on postback how are the values for each control get set back to the values which i have set earlier.
protected override void OnLoad( EventArgs e ){

// Put user code to initialize the page here

if(!IsPostBack)

{

TextBox1.Text = "wEQ";

}

}

Here I am checking for IsPostBack so I am not setting them again. I thought this cam for ViewState but cant see these there.

Or am i completely wrong here and ViewState doesnot do all this?

Thanks

Sourabh

Nov 18 '05 #2
> So the confussion is on postback how are the values for each control get set
back to the values which i have set earlier.


For TextBoxes and DropDownLists, the values posted back by the page are
NOT stored in view state*. This is because the values are posted back
from the browser (the value attributes of the <input> elements for the
textboxes, and the value attribute from the selected <option> element in
the <select> element for DropDownLists).

What you might want to do is grab a copy of Reflector
[http://www.aisto.com/roeder/dotnet/] and check out how the TextBox and
other Web controls implement LoadViewState. Also, a highly recommended,
must-read book for control development is Developing Microsoft ASP.NET
Server Controls and Components
[http://www.4GuysFromRolla.com/ASPScr...to.asp?ID=170]

Lastly, I have recently authored an article on view state for MSDN's
ASP.NET Dev Center. The article has yet to be published, but if you
shoot me an email I'd be happy to send you a draft version of the
article. It might help clear up some confusion.

Hope this helps, and happy programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
Nov 18 '05 #3

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

Similar topics

4
by: Johnny Emde | last post by:
Hello Newsgroup I'm about going nuts!!! Sometime when I coding a asp.net (using C#) I'll get this wierd error. Configuration Error Description: An error occurred during the processing of a...
6
by: Frank | last post by:
Can someone please tell me when the ViewState is loaded? My understanding, based on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconControlExecutionLifecycle.asp...
1
by: shapper | last post by:
Hello, I have a class where I created various controls. One of the controls have a property which is a generic list of WebControl. Then in web site page I have something like: Dim a As New...
5
by: Shelly | last post by:
This ASPX/SqlServer stuff is driving me nuts. 1 - In a previous post I said I had four tables and all were showing up in Object Explorer (MS SQL Server Management Studio Express), but when I went...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.