我如何保存ASP:跨回传HiddenField价值? [英] How can I save asp:HiddenField value across postback?

查看:116
本文介绍了我如何保存ASP:跨回传HiddenField价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何保存ASP:HiddenField值回发各地

How can I save asp:HiddenField value across postback?

推荐答案

这已无关的ViewState。表单控件的值是做一个POST维护。只要创建足够早在页面生命周期的控制,张贴值将在控制设置。如果你刷新页面或者点击,做一个GET超链接,则该值将丢失或恢复到设计器生成的默认值。

This has nothing to do with ViewState. A form control's value is maintained by doing a POST. As long as the control is created early enough in the page lifecycle, the posted value will be set on the control. If you refresh the page or click on a hyperlink that does a GET, then the value will be lost or revert to the designer-generated default.

回到你的问题,如果你有一个设计器生成的 HiddenField (在aspx文件),它会自动设置回传的值。无论你在别的地方改变它在你的code,或者您试图访问值被设置前(即前的Page_Load())。如果你有一个code产生的 HiddenField ,它需要有相同的ID和创建的页面设置发布的值,如<$ C $前C>的OnInit 。

Back to your question, if you have a designer-generated HiddenField (in the aspx file), it should automatically set the value on postback. Either you're changing it somewhere else in your code or you are trying to access the value before it has been set (i.e. before Page_Load()). If you have a code-generated HiddenField, it needs to have the same ID and be created before the Page sets the posted values, such as in OnInit.

我建议你通过阅读并理解以下文章。否则,你会不断撞击墙壁,因为页面生命周期和ViewState中是至关重要的。

I would recommend you read through and understand the following articles. Otherwise, you will keep hitting walls because the Page lifecycle and ViewState are fundamental.

<一个href=\"http://msdn.microsoft.com/en-us/library/ms972976.aspx\">http://msdn.microsoft.com/en-us/library/ms972976.aspx

<一个href=\"http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx\">http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx

这篇关于我如何保存ASP:跨回传HiddenField价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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