Disable Viewstate

  • Thread starter Thread starter MCM
  • Start date Start date
re:
!> What controls specifically (other than gridview, which I am not using)
!> could cause viewstate to grow?

All/any of them, as I explained in my last reply to this thread.
I also posted specifics to help you get rid of ViewState in any control.

Give that a try, will you ?



Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
MCM said:
I understand how viewstate works. That is not my question.

**I already have <pages enableViewState="false"> in my web.config.**

What controls specifically (other than gridview, which I am not using) could
cause viewstate to grow?



Allen Chen said:
Hi,
I already have <pages enableViewState="false"> in my web.config. And none of
the controls have a gridview. What other things use viewstate/controlstate
other than gridview?

Thanks for your update. Almost all of the built-in ASP.NET controls uses
ViewState and some of the built-in controls such as GridView also use
ControlState. For example, the Label controls only uses ViewState to
persist data for the Text property:

public virtual string Text
{
get
{
object obj2 = this.ViewState["Text"];
if (obj2 != null)
{
return (string) obj2;
}
return string.Empty;
}
set
{
if (this.HasControls())
{
this.Controls.Clear();
}
this.ViewState["Text"] = value;
}
}

You can see ViewState is used. In addition, Label control overrides the
LoadViewState() method:

protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
base.LoadViewState(savedState);
string str = (string) this.ViewState["Text"];
if (str != null)
{
this.Text = str;
}
}
}

On postback, the Text property will be reassigned so if you change Text
property on a button click event handler, the changed string will persist
for all subsequent postbacks.

If you have additional questions please feel free to ask.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
I appreciate your help, but I am waiting to hear back from Allen Chen. I am
fully aware that all/any controls use viewstate. However, I have DISABLED
viewstate for the application globally in web.config. This is working fine on
most of my pages. On some of the pages that use User Controls (.ascx files),
the viewstate is very large. I understand that there is something called
ControlState that uses the ViewState field on the client side to store data.
And that a control such as gridview uses that ControlState. My question is,
other than gridview - since I am not using it - could be using ViewState even
though I have it disabled.


Juan T. Llibre said:
re:
!> What controls specifically (other than gridview, which I am not using)
!> could cause viewstate to grow?

All/any of them, as I explained in my last reply to this thread.
I also posted specifics to help you get rid of ViewState in any control.

Give that a try, will you ?



Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
MCM said:
I understand how viewstate works. That is not my question.

**I already have <pages enableViewState="false"> in my web.config.**

What controls specifically (other than gridview, which I am not using) could
cause viewstate to grow?



Allen Chen said:
Hi,

I already have <pages enableViewState="false"> in my web.config. And none
of
the controls have a gridview. What other things use viewstate/controlstate
other than gridview?

Thanks for your update. Almost all of the built-in ASP.NET controls uses
ViewState and some of the built-in controls such as GridView also use
ControlState. For example, the Label controls only uses ViewState to
persist data for the Text property:

public virtual string Text
{
get
{
object obj2 = this.ViewState["Text"];
if (obj2 != null)
{
return (string) obj2;
}
return string.Empty;
}
set
{
if (this.HasControls())
{
this.Controls.Clear();
}
this.ViewState["Text"] = value;
}
}

You can see ViewState is used. In addition, Label control overrides the
LoadViewState() method:

protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
base.LoadViewState(savedState);
string str = (string) this.ViewState["Text"];
if (str != null)
{
this.Text = str;
}
}
}

On postback, the Text property will be reassigned so if you change Text
property on a button click event handler, the changed string will persist
for all subsequent postbacks.

If you have additional questions please feel free to ask.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
re:
!>I appreciate your help, but I am waiting to hear back from Allen Chen.

If I were you, I'd take advice from wherever I get it from.

re:
!> I have DISABLED viewstate for the application globally in web.config.

No, you have not disabled it GLOBALLY.

You have disabled it at the page class level, which means that
anything which inherits from page will not have ViewState available.

Everything else still has ViewState, though, until you specifically disable it.

re:
!> other than gridview - since I am not using it - could be using ViewState

All of them...until you disable ViewState for all controls.

re:
!> even though I have it disabled

You have NOT disabled it *globally*. See explanation above.




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
MCM said:
I appreciate your help, but I am waiting to hear back from Allen Chen. I am
fully aware that all/any controls use viewstate. However, I have DISABLED
viewstate for the application globally in web.config. This is working fine on
most of my pages. On some of the pages that use User Controls (.ascx files),
the viewstate is very large. I understand that there is something called
ControlState that uses the ViewState field on the client side to store data.
And that a control such as gridview uses that ControlState. My question is,
other than gridview - since I am not using it - could be using ViewState even
though I have it disabled.


re:
!> What controls specifically (other than gridview, which I am not using)
!> could cause viewstate to grow?

All/any of them, as I explained in my last reply to this thread.
I also posted specifics to help you get rid of ViewState in any control.

Give that a try, will you ?



Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
MCM said:
I understand how viewstate works. That is not my question.

**I already have <pages enableViewState="false"> in my web.config.**

What controls specifically (other than gridview, which I am not using) could
cause viewstate to grow?



:

Hi,

I already have <pages enableViewState="false"> in my web.config. And none
of
the controls have a gridview. What other things use viewstate/controlstate
other than gridview?

Thanks for your update. Almost all of the built-in ASP.NET controls uses
ViewState and some of the built-in controls such as GridView also use
ControlState. For example, the Label controls only uses ViewState to
persist data for the Text property:

public virtual string Text
{
get
{
object obj2 = this.ViewState["Text"];
if (obj2 != null)
{
return (string) obj2;
}
return string.Empty;
}
set
{
if (this.HasControls())
{
this.Controls.Clear();
}
this.ViewState["Text"] = value;
}
}

You can see ViewState is used. In addition, Label control overrides the
LoadViewState() method:

protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
base.LoadViewState(savedState);
string str = (string) this.ViewState["Text"];
if (str != null)
{
this.Text = str;
}
}
}

On postback, the Text property will be reassigned so if you change Text
property on a button click event handler, the changed string will persist
for all subsequent postbacks.

If you have additional questions please feel free to ask.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
Hi,
I understand how viewstate works. That is not my question.
**I already have <pages enableViewState="false"> in my web.config.**
What controls specifically (other than gridview, which I am not using) could
cause viewstate to grow?

Thanks for your reply. Many data presenting controls uses ControlState as
well. For instance, FormView, DetailsView, etc. All this kind of controls
would increase ViewState size even if you disabled ViewState.

Could you send me a simple demo project? You can add one UserControl that
increases the ViewState size. I'd like to explain based on the demo
project. In this way I think we can quickly solve this issue. My email is
(e-mail address removed). Please update here after sending the project in case
I missed that email.

Regards,
Allen Chen
Microsoft Online Support
 
Hi,
I understand how viewstate works. That is not my question.
**I already have <pages enableViewState="false"> in my web.config.**
What controls specifically (other than gridview, which I am not using) could
cause viewstate to grow?

Have you sent me a demo project? We can discuss based on this project.
Please update here after sending the project in case I missed that email.

Regards,
Allen Chen
Microsoft Online Support
 
Back
Top