473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1035
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******** ********@TK2MSF TNGP11.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******@4guysf romrolla.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
1220
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 configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
6
1274
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 is that it should be loaded before the Page_Load event, however, given the following code I don't get the expected results. private void Page_Load(object sender, System.EventArgs e) { if (Page.IsPostBack & ViewState != null)
1
1335
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 MyNamespace.ListItem a.WebControls.Add(tbName) a.WebControls.Add(lLabel)
5
1407
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 to do a query using the query text editor, only two of the tables showed up. Then, mysteriously, the problem went away. Now, it is back. 2 - My insert into a table failed from the debug version in Web Developer, so I copied that SQL call and...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
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...
1
8518
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
8621
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...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
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
5643
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();...
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.