我怎么能取消的ViewState没有控制问题 [英] How I can deactivate ViewState without Control problems

查看:107
本文介绍了我怎么能取消的ViewState没有控制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个ASP.NET应用程序,并在服务器IIS7的运行。如果我在浏览器中打开此网页表单,并告诉我的网站code我看到这...

I wrote a ASP.NET Application and it run in IIS7 of a Server. If I open this webform in my Browser and show me the Sitecode I see this...

我有很多控制如何按钮,标签,文本框和一个ListView。我试着在web.config停用ViewState的,但如果我停用此我的应用程序不能正确运行。我能做什么?

I have many Controls how Buttons,Labels,TextBoxes and a ListView. I try to deactivate ViewState in the web.config but if I deactivate this my Application don't run correctly. What can I do?

推荐答案

停用只是不需要视图状态的控件。

Deactivate only the controls that not need the viewstate.

要做到这一点,你需要了解视图状态是什么。

To do that you need to understand what the viewstate is.

视图状态就是将网页保存并记住控件的值回发后,有他们。请记住,视图状态是一个回后使用。

Viewstate is where the page save and remember the values of the controls to have them after a post back. Remember that, the viewstate is used after a post back.

因此​​,实际上你有两次相同的数据,但只有视图状态回发的previous数据和code后面可以使用这些数据。

So actually you have two times the same data, but only the viewstate is post back the previous data and code behind can be use that data.

所以,主要的问题是,什么样的控制你必须记得你有填充它们,或者什么控件需要remeber他们的previous状态。

So the main question is, what controls do you need to be remember what you have fill them in, or what controls need to remeber the previous state of them.

让我们来看看一个简单的文字用的EnableViewState和关闭。

Lets see a simple Literal with EnableViewState on and off.

<asp:Literal runat="server" EnableViewState="true" ID="txtLiterar">

现在,如果你放在这个文字文本的文本也将保存在视图状态和code后面你可以做到这一点。

Now if you place a text on this literal the text is also saved on viewstate and on code behind you can do that.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        txtLiterar.Text = "Hello There";
    }
}

所以,后门柱后面的文字仍然有它的内容,你能避免再次填满它,因为有视图状态并自动重新填充。

So after the post back the Literal still have its content, and you can avoid to fill it again, because the viewstate have it and automatically fills it again.

<asp:Literal runat="server" EnableViewState="false" ID="txtLiterar">

现在,如果你放在这个文字文本的文本不会被保存在视图状态和code你后面添加为。

Now if you place a text on this literal the text is not saved on view state and on code behind you add it as.

protected void Page_Load(object sender, EventArgs e)
{
    txtLiterar.Text = "Hello There";
}

所以,不同的是,你需要填写总是对每一个岗位的数据的控制。

So the different is that you need to always fill that control with data on every post.

视图状态的最需要的部分是,当你填写的下拉列表。有你有背后需要记住值的SelectValue将正确的一个数据绑定和code。

The most needed part of the viewstate is when you fill a dropdown list. There you have a databind and code behind need to remember the values to place on the SelectValue the correct one.

它也需要在GridView和其他控件一样,因为是保持previous页面,当你分页数据等信息的。

Its also needed on GridView and other controls like that because is keep the previous page and other information's when you paging your data.

所以,你可以在大部分的控制关闭视图状态 - 对控制,你可以在每一个岗位重新填写他们回来,和一个控制不需要remeber的previous状态

So you can close on most of your controls the viewstate - on that controls that you can fill them again on every post back, and on that controls that not need to remeber the previous state.

更多阅读:结果
如何优化类视图状态结果
<一href=\"http://stackoverflow.com/questions/4046805/determine-size-of-asp-net-pages-viewstate-before-serving-page\">Determine ASP.NET页面的ViewState的大小之前服务页面结果
<一href=\"http://stackoverflow.com/questions/8877252/limiting-view-state-information-on-ajax-calls\">Limiting AJAX的视图状态信息调用

More to read:
How to optimize class for viewstate
Determine size of ASP.NET page's viewstate before serving page
Limiting view state information on AJAX calls

这篇关于我怎么能取消的ViewState没有控制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆