gpt4 book ai didi

c# - Viewstate 上的 TextBox 值?

转载 作者:行者123 更新时间:2023-11-30 17:13:45 25 4
gpt4 key购买 nike

回传中的文本框值不会保留在 View 状态中。

http://msdn.microsoft.com/en-us/library/ms972976.aspx

When the ASP.NET Web page is posted back in the load postback datastage, the Page class sees that one of the posted back form fieldscorresponds to the IPostBackDataHandler interface. There is such acontrol in the hierarchy, so the TextBox's LoadPostData() method isinvoked, passing in the value the user entered into the TextBox("Hello, World!"). The TextBox's LoadPostData() method simply assignsthis passed in value to its Text property. the values are identifiedvia posted back form field values, and assigned in the LoadPostData()method for those controls that implement IPostBackDataHandler.

现在让我们谈谈TextBox.OnTextChanged Method

上面写着:

Note

A TextBox control must persist some values between posts to theserver for this event to work correctly. Be sure that view state isenabled for this control.

问题:

所以我猜对于某些事件,它确实会写入 Viewstate...

它如何告诉 ASP.NET “开始跟踪对 Viewsstate 的更改”

最佳答案

当您为 TextBox 启用 ViewState 时,它​​将简单地保存在那里。


ASPX 页面示例

 <asp:TextBox ID="tb" runat="server" EnableViewState="true"></asp:TextBox>

C#(代码隐藏)示例

tb.EnableViewState = true;

您的引述谈到了这样一个事实,即在回发时恢复表单时不需要此值。

因此您可以关闭 TextBox 的 ViewState,它仍将保留其值。但是 OnChanged 将不起作用。

关于c# - Viewstate 上的 TextBox 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9515631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com