.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

ViewState confusion

Posted By:      Posted Date: September 14, 2010    Points: 0   Category :ASP.Net
I have been reading an article about ViewState and page's life cycle by Scott Mitchell which was published on May 2004. Here is the link: http://msdn.microsoft.com/en-us/library/ms972976.aspx First of all, I would like to know if the concepts he has explained still hold true in the latest versions of ASP.NET and IIS. Also, I tried a simple page to see how it works in real. According to the article, what needs to be stored in view state is any programmatic changes to page's state. Ok I created a very simple page (in ASP.NET 3.5 and IIS 7.0) containing a text box with initial value of 'A', two button, first changes the text box value to 'B', the second only posts the page back. I set the EnableViewState value of the textbox to false. I first clicked the first button, it changed the value of the textbox to 'B', and after clicking the second button, I expected the value of the textbox to change back to 'A' (According to what was explained in the article, depicted with a graph). But the value remained 'B'. This has caused me a lot of confusion. Maybe I haven't understood the whole thing correctly. Please someone explain this.

View Complete Post

More Related Resource Links

Composite Control which contains arbitrary content defined in .aspx of parent and thier ViewState


I want to write own control which can contain other. And I want to define content of the control in the .aspx file where the control is defined. I have written such control. But now I have issue with ViewState of inner controls of my control. The following samle illustrates the issue: I defined two asp:DropDownList ID="ddl1" and ID="ddl2" One of them is inside of my control and other is outside. When posback is occurred asp:DropDownList ID="ddl1 loses state and becomes empty. How to say ASP.net to store state of inner controls defined by this way?


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="DynamicControls.Controls.MyControl" %>

<div class="box">
    <div class="Header-Left">
        <div class="Header-Right">
            My Control
    <div class="Content">
        <asp:PlaceHolder ID="contentPlace" runat="Server" />

Editor's Note: Code Name Confusion


We'd like to have a word about product code names this month.

MSDN Magazine February 2006

EntityDataSource Where Clause in ViewState?



I have ListView/DataPager on the page that I use together with an EntityDataSource, because I want to filter the results, I programmatically set the Where-property and the WhereParameters of the EntityDataSource.

But: After the Paging-Postback the Value for Where is gone (empty string) whereas the WhereParameters are still there. Isn't the where value saved in ViewState as well? Can I change this behaviour?

Thanx, S.

Custom controls and ViewState management issue



I want to know that when we create custom controls, then is there State Management through ViewState done automatically or we have to handle it explicitely ?Since i have created Custom Controls that is behaving as if it is not maintaining its state on PostBack.

viewstate in a custom control

I am having issues with a simple custom control that I created by subclassing the hyperlink control.

I wanted to create a control called BackLink that would automatically grab the referring url to the page when it first loads the page. and on postbacks it would continue to use the initial value

I am able to capture and set the navigateurl property when the containing page first loads just fine but if the page submits to itself, the control loses its navigateurl value.

I have the enableviewstate property set in the aspx page but it doesn't seem to want to keep its viewstate

Am I missing something? Do I have to manage my own ViewState?

here is my code

public class BackLink : System.Web.UI.WebControls.HyperLink

public BackLink()
this.Text = "<< back";

protected override void Render(HtmlTextWriter output)
if (this.Page.IsPostBack == false)
//save back url
Uri _backUri = this.Context.Request.UrlReferrer;

if(_backUri != null) this.NavigateUrl = _backUri.PathAndQuery;

else this.NavigateUrl = "/";

IIS - sharepoint/default website port number confusion



I have MOSS 2007 installed with IIS V7.

My default web site port is 80. When I created a new web application for my main sharepoint portal I also set it to 80. So obviously now the default web site port shows as stopped in IIS and it won't start.

What are the best practices. Should I change the port number for my portal to something else? I mean is it even a good idea to have sharepoint on port 80? If so, how do I go about changing the port number for my portal site?

any help appreciated.

SharePoint and "Help Desk" template confusion

Okay; so I've read the three posts I found on this forum about the SharePoint Services "Help Desk" administrative template. I've scoured the internet for nuggets of wisdom; all-in-all, I've come to the conclusion that there is hardly ANY documentation for this template! :) So please excuse me if this question is considerd "noobish-ish" by some--I just a looking for a fresh set of brain cells to bounce my question off of. The template, itself, seems pretty bare bones and to the point, as far as ticketing issues. But how in the site settings do I specify a Service Request, when a domain user clicks on the "Create a Service Request " link, to go to a specific help desk email account on our Active Directory network? I see "Create a Service Request," "Service request List," "Service Request Task List;" it's getting a little confusing, as I don't use the "portal" end of SP, as much as I administrate our server. Where should I start, one and all?? ANY help will be greatly appreciated; thank you!

Confusion between sizeof(long) and LLP64

Hi, I have found the following information on MSDN "In the LLP64 data model, only pointers expand to 64 bits; all other basic data types (integer and long) remain 32 bits in length. The .NET CLR for 64-bit platforms uses the same LLP64 abstract data model." This implies that the size of long on 32 as well as 64 bit systems should be 32 bits. But when I use a long in my application, I find the underlying type to be System.Int64 and sizeof(long) returns the value of 8 implying 64 bits. I have observed this behavior on 32 bit as well as 64 bit systems. This is contradictory to the information on MSDN. Please let me know what am I missing here. Thanks, Mayur

POST from html form viewstate problem

<p> Hi all, I have a website where people need to pay for a specific download (.pdf file). After they payed they get the download(A). My payment-provider can do a HTML-Postback to the site i want, for each succesfull payment. So the idea is that if someone payed, they do a postback to my server with a couple of parameters, so i can know that that specific email address has payed, and they get the download. I tested localy with a .html file on my desktop to postback a set of parameters to my local asp.net website. But in ONLY works if i include the __VIEWSTATE in my html file. And i cant get rid of the viewstate in my HTML of the aspx page. >test.html: <html><head></head><body> <h1>Dit is een test</h1> <form id="form1" action="http://localhost:25659/WebForm1.aspx" method="POST"> <input id="Button1" type="submit" value="submit!"/> 'IT ONLY WORKS IF I INCLUDE THE NEXT LINE: <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNGRk" /> </form></body></html> Has anybody an idea to acomplish my goal? Maybe i can get some info about the postback in my global.asax? or create a HttpHandler for .html files? Anyone?   Thanks in advance, Vincent   </p>

How to avoid viewstate in page load event??

Hello Everyone, Here Is my scenario,I haveMaster Page -> ASPX page -> User ControlUser control page is contains all dynamic bind controls (e.g Repeater) depended on ASPX Page (Only one parameter say ItemNo) The problem is, if I bound user control on page load event with passing respective parameters then it's create to much view state (I checked source file and it's almost 1.5 MB) In other way if I put one textbox, and a command button and I pass required parameter on button click and load the control then page size is ok (I checked and it's  < 500KB) So is it any way I can reduce my page/state size??

Invalid viewstate - AGAIN.

I'm getting 100+ errors per day on my website with System.Web.HttpException: Invalid viewstate. at System.Web.UI.Page.DecryptStringWithIV The website is asp.net 3.5 running on iis6 , not running in a web-garden/web-farm , single server. The website is using xhtml doctype. viewstate size vary from 2kb-20kb Here are a few sample errors.Machine: ML Framework Version: 2.0.50727.3603 Assembly Version: 6.5.3664.33889 Source: http://www.domain.com/WebResource.axd?d=z5VmXXoSLLpQHoPictureAlert Exception: System.Web.HttpException: Invalid viewstate. at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType) at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) Machine: MLFramework Version: 2.0.50727.3603 Assembly Version: 6.5.3664.33889 Source: http://www.mydomain.com/ScriptResource.axd?d=SE0Ej7OlEAx91j2Cjv_6KkRPplqT-5wB4M7CZPdGdGn3LahLwqlRPApUcdxBsbFXYHZ91Q76FHAHWgHs8SmOC4zemr7 siym0QY0rF3XtJTu%3C/a%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ca%20id= Exception: System.Web.HttpException: Invalid viewstate. at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType)

WebPart has empty viewstate on postback

I have a simple weather web part in the form of a user control.  This usercontrol has an update panel and a textbox to allow the user to enter in a zip code/ city etc and an ok button.  The problem comes in when the webpart is added or dragged outside of Zone 1.  If this webpart remains in Zone 1 everything is fine.  If it is in Zone 2 or 3 after entering a zip code and hitting ok and posting back the value of the textbox is always blank.  It seems like the viewstate is cleared or the control is loading for the first time.  I have checked the Page.IsPostBack property and it is indeed True.  What would cause my control to loose the value entered in the textbox only when it resides outside of Zone 1?

Access ViewState in Class File

The article Access ViewState in Class File was added by bhaarat on Wednesday, September 01, 2010.Many times we might need to access Viewstates in classfilewhich is not availablethis is a way to access the Viewstte in Class fileon code Behind%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits

Validation of viewstate MAC failed

Hi Experts,I have received an error "Validation of viewstate MAC failed".I am hosting the web site on my own server, so there is nothing like a "Web Farm or cluster". Can you please advise what could be the problem with this error.I only get this error if the page is left inactive for more then 20 minutes and it throws the exception, so users have log-off and login to continue working fine.See below full error details. Server Error in '/datacapv2' Application. Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. Source Error: The source code that generated this unhandled exceptio

gridview values confusion

hi guysi have one page "Search" where the user can search based on the name of the customerI have another page that contains the details for that customermy question is that on the top of the second page i would like to have the name of the customer that the user search for.so the page would look like this                   JOHN JOHNSONDob    .......Tel ........etcwhen i try to create a gridview to bring the value of the name on the top of the page i get confused because the WHERE clause only allows me to select from textboxes included in that page and not on another pagehow can i overcome this?

Process.Start return value confusion

MSDN documentation for Process.Start return value says: A new Process component that is associated with the process resource, or null if no process resource is started (for example, if an existing process is reused). What does "existing process is reused" mean? When can it happen?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend