的EnableViewState = QUOT假QUOT;不生效? [英] EnableViewState="False" Does not take effect?

查看:99
本文介绍了的EnableViewState = QUOT假QUOT;不生效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部


我创建一个ASP.NET页面,它包含FirstName文本框和LastName

文本框。我设置了enableViewState = false在页面指令中。当我在FirstName和LastName文本框中输入

数据后,刷新页面或转到

不同页面并返回同一页面后,我发现输入的数据在

FirstName和LastName文本框仍然存在。


我认为在设置后enableViewState = false我们移动到另一个页面然后回来后,我们不打算在文本框中看到数据




请帮忙。


谢谢



Hi, All

I create an ASP.NET page, it contains FirstName textbox and LastName
textbox. I setup "enableViewState=false" in page directive. When I enter
data in FirstName and LastName textbox, after I refresh the page or go to
different page and come back to the same page, I find data entered in
FirstName and LastName textbox are still there.

I think after setup "enableViewState=false" , we are not suppose to see data
in the textbox after we move to another page and come back?

Please help.

Thanks

Kai

推荐答案



禁用ViewState对TextBox没有影响..


查看我的博客文章以获得解释
http://blogs.aspadvice.com/joteke/ar...03/15/ 767.aspx


这与发布行为有关(当页面发布回自身时),但

你说回来相同的页面。您是否正在访问另一个完全单独的ASP.NET页面,然后返回到包含

TextBoxes的原始页面,它们仍保持状态!?


-

Teemu Keiski

MCP,Microsoft MVP(ASP.NET),AspInsiders成员

ASP.NET论坛版主,AspAlliance专栏作家
http://blogs.aspadvice.com/joteke

" kai" < KA ****** @ earthlink.net>在消息中写道

新闻:IL ***************** @ newsread3.news.atl.earthl ink.net ...
Hi,

disabling ViewState has no effect on TextBox..

Take a look at my blog post for an explanation
http://blogs.aspadvice.com/joteke/ar...03/15/767.aspx

This relates to the posting behaviour (when page posts back to itself), but
you said "come back to the same page". Are you visiting another completely
separate ASP.NET page and then return to the original Page containing
TextBoxes and they still keep the state!?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"kai" <ka******@earthlink.net> wrote in message
news:IL*****************@newsread3.news.atl.earthl ink.net...
全部

我创建了一个ASP.NET页面,它包含FirstName文本框和LastName
文本框。我设置了enableViewState = false在页面指令中。当我在FirstName和LastName文本框中输入数据时,刷新页面或转到
不同页面并返回同一页面后,我发现在FirstName和LastName文本框中输入的数据是仍然存在。

我认为在设置之后enableViewState = false我们移动到另一页并回来后,我们不会在文本框中看到
数据?

请帮忙。

谢谢

Kai
Hi, All

I create an ASP.NET page, it contains FirstName textbox and LastName
textbox. I setup "enableViewState=false" in page directive. When I enter
data in FirstName and LastName textbox, after I refresh the page or go to
different page and come back to the same page, I find data entered in
FirstName and LastName textbox are still there.

I think after setup "enableViewState=false" , we are not suppose to see data in the textbox after we move to another page and come back?

Please help.

Thanks

Kai



Hi Kai,


根据您的描述,您发现输入ASP.NET文本框控件

值将在发回后保留,无论页面的视图状态是否支持
,是吗?是的?


至于这个问题,这是我的理解:

实际上,页面的视图状态确实被禁用了。

服务器端的任何设置都不能保留在回发之间。例如,您尝试使用以下代码(当页面的视图状态被禁用时):

private void Page_Load(object sender,System.EventArgs e)

{

if(!IsPostBack)

{

TextBox1.TextMode = TextBoxMode.Password;

}

}


然后,当页面第一次加载时,TextBox1是一个密码模式。

如果你回发页面(添加一个提交按钮),你会发现TextBox1的

模式转回正常(单行)。


然后,你必须弄清楚为什么文本框中的值保留在帖子

之后,是吗?这是因为在回发后使用

TextBox渲染输入的值。例如,当页面被回发时,在

服务器端,文本框将通过以下步骤:

1.其控制实例被构建


2.从视图状态恢复状态


3.将状态与其新的输入值进行比较(这是我们的新值

get实际上在Request.Form集合中)


4.将文本框的状态(值)更改为新值


5 ....处理文本框的回发事件(如果存在)


6.文本框以新值呈现(当页面为
渲染出来。


#6是新值保留的关键点,因为文本框

被渲染为包含新值的html元素,例如

< input type =" text" value =" new value" /> ;,不需要viewstate。你觉得

如此?


如果你有什么不清楚的地方,请随时在这里发布。谢谢。


问候,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)


在ASP.NET上获取预览whidbey
< a rel =nofollowhref =http://msdn.microsoft.com/asp.net/whidbey/default.aspxtarget =_ blank> http://msdn.microsoft.com/asp.net/whidbey /default.aspx

Hi Kai,

From your description, you found that the ASP.NET textbox control''s entered
value will remain after posted back no matter the page''s viewstate is
enabled or not ,yes?

As for this problem, here are my understanding:
In fact ,the page''s viewstate is really disabled. And any setting on the
serverside won''t be able to remain between post backs. For example, you try
the following code(when page''s viewstate is disabled):
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
TextBox1.TextMode = TextBoxMode.Password;
}
}

Then, when the page is first time loaded, the TextBox1 is a password mode.
If you post back the page(add a submit button), you''ll find the TextBox1''s
mode turn back to normal(singleline).

Then, you must be confused why the value in the textbox remains after post
back, yes? This is because the entered value is rendered out with the
TextBox after post back. For example, when the page is posted back, at the
serverside, the textbox will pass through the following steps:
1. its control instance be contructed

2. Restore its states from the viewstate

3. Compare the states with its new inputed value( this is the new value we
get which is actually in the Request.Form collection)

4. Change the textbox''s state(value) to the new value

5.... process the textbox''s postback event( if exist)

6. The textbox is rendered with the new value (when the page is
renderedout).

The #6 is the key point why the new value will remain , because the textbox
is rendered out as html element which has contain the new value such as
<input type="text" value="new value" />, no viewstate needed. Do you think
so?

If you have anything unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



Teemu

感谢您的帮助。我看了你的页面说明。

是的,我完全访问了另一个ASP.NET页面,当我向后导航时,数据

仍然在文本框和单选按钮中。 />
仅清除密码字段数据。


谢谢



" Teemu Keiski" <乔**** @ aspalliance.com>在留言中写道

news:uj ************** @ TK2MSFTNGP11.phx.gbl ...
Hi, Teemu
Thanks for helping me. I read your page explanation.
Yes, I visit completely another ASP.NET page, when I navigate back, data
still ramain in the textboxs and radio button.
Only password field data cleared.

Thanks
Kai
"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...

禁用ViewState对TextBox没有影响..

看看我的博客文章解释
http://blogs.aspadvice.com/joteke/ar...03/15/767.aspx

这与发布行为有关(当页面发布回自身时),
,但你说回到同一页面。您是否正在访问另一个完全单独的ASP.NET页面,然后返回到包含
TextBoxes的原始页面,并且它们仍保持状态!?

-
Teemu Keiski
MCP,Microsoft MVP(ASP.NET),AspInsiders成员
ASP.NET论坛版主,AspAlliance专栏作家
http://blogs.aspadvice.com/joteke

" kai" < KA ****** @ earthlink.net>在消息中写道
新闻:IL ***************** @ newsread3.news.atl.earthl ink.net ...
Hi,

disabling ViewState has no effect on TextBox..

Take a look at my blog post for an explanation
http://blogs.aspadvice.com/joteke/ar...03/15/767.aspx

This relates to the posting behaviour (when page posts back to itself), but you said "come back to the same page". Are you visiting another completely
separate ASP.NET page and then return to the original Page containing
TextBoxes and they still keep the state!?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"kai" <ka******@earthlink.net> wrote in message
news:IL*****************@newsread3.news.atl.earthl ink.net...
你好,All

我创建了一个ASP.NET页面,它包含FirstName文本框和LastName
文本框。我设置了enableViewState = false在页面指令中。当我在FirstName和LastName文本框中输入数据时,刷新页面或将
转到不同页面并返回同一页面后,我发现在FirstName和LastName文本框中输入的数据是仍然存在。

我认为在设置之后enableViewState = false ,我们移动到另一个页面然后回来后,我们不会在文本框中看到
Hi, All

I create an ASP.NET page, it contains FirstName textbox and LastName
textbox. I setup "enableViewState=false" in page directive. When I enter
data in FirstName and LastName textbox, after I refresh the page or go to different page and come back to the same page, I find data entered in
FirstName and LastName textbox are still there.

I think after setup "enableViewState=false" , we are not suppose to see


数据

吗?

请帮忙。 />
谢谢


in the textbox after we move to another page and come back?

Please help.

Thanks

Kai




这篇关于的EnableViewState = QUOT假QUOT;不生效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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