Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Viewstate

  Asked By: Anpu    Date: Jun 13    Category: Asp.net    Views: 557
  

I have a two part question regarding Viewstate. First part is how to
enable or disable viewstate for individual controls on a web form.

If you have enableViewState set to true for the document can you
still disable viewstate for each control?

If you take off the EnableViewState at the document level can you
still enable viewstate for individual controls?

The problem I am encountering is with dynamically created controls at
runtime. I am building a details table with rows and columns and
putting dropdownlist and textboxes into cells of the table. The
number of rows in the table depends on how many rows are returned in
a dataset. Each control will always be assigned the same ID with
the row number appended. When I navigate to a new detail record the
dynamically created controls will have the same ID and they are being
set to the old values from the previously created detail table.

Any ideas on how to stop the viewstate from doing this. I have tried
to set EnableViewState to False for the table the panel the table is
in and for each individual control.

Share: 

 

12 Answers Found

 
Answer #1    Answered By: Devrim Yilmaz     Answered On: Jun 13

Is there a way to reduce the size of the Viewstate? When using <form
runat="server">, I want the functionality that using Viewstate gives me,
but does it have to be that large it often is? The size is 40000
characters (and that will slow down the speed of the site, I think?)!

Is there any way to reduce the size?

 
Answer #2    Answered By: Ella Brown     Answered On: Jun 13

Depending on what functionality you need. You can disable viewstate  on a "per
control" basis by setting controlname.EnableViewState = false

If you would just like the postback functionality for a form  you can override
viewstate all together.
Then you don't even need to user a server side form.
NOTE: this has odd side effects. Like HtmlInputImages cannot raise the
ServerClick event.

C# code


protected override object LoadPageStateFromPersistenceMedium()
{
return null;
}
protected override NameValueCollection DeterminePostBackMode()
{
if(Request.Form.Count > 0)
{
return Request.Form;
}
return null;
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
// Do nothing.
}

 
Answer #3    Answered By: Liam Bouchard     Answered On: Jun 13

yes, turn it off...

viewstate=off

 
Answer #4    Answered By: Hababah Younis     Answered On: Jun 13

I have now turned it off by writing

<%@ Page EnableViewState="false" %>

on the top of the page, and the viewstate  was really reduced ;-)

But there is one thing that confuses me:

I have a form  with some fields. After posting the form, it still
remembers the content of the fields. Why is the content remembered when
the viewstate is turned off?

 
Answer #5    Answered By: Edfu Massri     Answered On: Jun 13

Form submission and Viewstate are 2 different things.
Viewstate is Microsoft's attempt at remembering data
that is in the form  Inputs so when you come back after
submitting the form, it still keeps whatever was
input.

Pretty bare bones explanation that someone else on
this list could expound on or alter to be more
precise.

 
Answer #6    Answered By: Samuel Costa     Answered On: Jun 13

When i try to view my aspx page i get the following error:
The viewstate  is invalid for this page and might be corrupted.
What could cause it? I had the same error a few days ago with a different page
but after restarting the computer i was able to view my page. This time however
i can't view my page.

 
Answer #7    Answered By: Dirck Jansen     Answered On: Jun 13

support.microsoft.com/default.aspx?kbid=323744
has something to say about this error. Look for other
fixes on microsoft.com.

 
Answer #8    Answered By: Calais Bernard     Answered On: Jun 13

you can try enableviewsatemac=false at the page directives .
This may solve your problem

 
Answer #9    Answered By: Calvin Banks     Answered On: Jun 13

I get the following error:
The 'enableviewsatemac' attribute is not supported by the 'page' directive.

 
Answer #10    Answered By: Ralph Murray     Answered On: Jun 13

ok i managed to do the enableviewstate thingy :-) but i still get
The viewstate  is invalid for this page and might be corrupted.
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: The viewstate is invalid for this
page and might be corrupted.

Source Error:


An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page and might be
corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +150
System.Web.UI.Page.LoadPageViewState() +18
System.Web.UI.Page.ProcessRequestMain() +423

 
Answer #11    Answered By: Keith Marshall     Answered On: Jun 13

Four alternatives i can think of (the fourth one may
be a bit drastic, but you never know) :-

1) Search the archives of this list for the error, and
take some action.
2) Search microsoft.com for the error.
3) Try repairing the .NET installation
4) Remove and re-install the .NET installation.

 
Answer #12    Answered By: Timothy Patterson     Answered On: Jun 13

I get to the page that gives me the problems from a previous page-nav.aspx that
only has buttons and each button is directed to a different page. All the other
pages work fine only one page -payads.aspx gives me the viewstate  problem.
When i change the buttons onclick from
btnAds2Pay.Attributes.Add("onclick", "SbtForm ('payads'); return false;")

to:


Private Sub btnAds2Pay_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAds2Pay.Click

Server.Transfer("payads.aspx?aprst=1")

End Sub

it works but i don't want it to work that way. i want the
btnAds2Pay.Attributes.Add("onclick", "SbtForm ('payads'); return false;")

 
Didn't find what you were looking for? Find more on Viewstate Or get search suggestion and latest updates.




Tagged: