一直以来都有个困惑,设置了 ReadOnly="True" 的 TextBox 控件,如果使用 JavaScript 在客户端修改了值,页面提交后又恢复了原来的值。这是很令人郁闷的事儿。

现在,项目中又面临了这个问题,是时候做个了断。昨天,在完成了 GridViewHelper 的 80% 功能后,我反复尝试了很多方法,未果。项目组会议结束后,回家,吃饭,睡觉。

今天早晨在上班的公车上琢磨着用 CSS 设置 readonly,Google 了一下,未果。老外兄弟们都说No way to do it in CSS, do it in the markup tag or by script.

后来继续 Google,发现微软官方这样说:With a design change in ASP .NET based on user security concern, the input for a readonly textbox is saved in viewstate, which doesnt happen if viewstate is disabled. To workaround this, a page developer can add the readonly attribute to the TextBox.Attributes collection, which can then be used to access the 'value' of the textbox.

就是这样的,我们绕过 WebForm 的 ViewState,通过 HTML 的方式实现了这个功能,很方便。

相关文章:

  • 2021-09-21
  • 2022-02-24
  • 2022-02-23
  • 2022-12-23
  • 2021-08-20
  • 2022-02-01
猜你喜欢
  • 2021-10-22
  • 2022-12-23
  • 2021-07-14
  • 2021-10-22
  • 2022-12-23
  • 2021-12-03
  • 2021-07-24
相关资源
相似解决方案