像ASP控件一样保留HTML值 [英] Retain HTML value like an ASP control

查看:94
本文介绍了像ASP控件一样保留HTML值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,



我有一个web应用程序,其中有一个表单,我的表单有

产品代码:
< 输入 类型 = text 名称 = txtVpPrdCd maxlength = 15 style = text-transform:uppercase; / >







作为洙在我提交表单时,文本框中输入的值会清除。有没有办法可以保留像ASP控件那样的值。



非常感谢你的帮助

解决方案

基本上,您的ASP.NET代码使用未填充的数据生成HTML,空数据。但是在提交表单后,您在服务器端获得了一些数据。比如,它可以保存在数据库中。您需要使用此数据填写页面。表单提交后,您的表单将在HTTP响应中从头开始重新生成,因为这是表单的 action 属性告诉服务器的。它在HTTP请求中请求页面。如果这是与原始页面相同的页面,则将再次加载未填充的页面。使用您正在使用的APS.NET语法从数据中填充它。其他细节取决于您在服务器端的数据。



还有一种纯客户端方法,其中所有数据都存储在Web存储中: http://en.wikipedia.org/wiki/Web_storage [ ^ ]。



你只需要使用 sessionStorage 对象,以避免使用永久保存的数据污染浏览器数据。另一个问题是:如何在一个单独的密钥上存储一个数据。解决方案是:您可以使用JSON对象序列化它并反序列化回所有表单数据。我的文章中显示并解释了整个解决方案的示例代码;请参阅此部分: JavaScript计算器。 7。动态严格模式切换和Web存储



此客户端解决方案的好处在于它是通用的,不取决于您在服务器端的内容。它只是根据以前提交的数据填写控件,无论数据是什么以及如何在服务器端呈现。



- SA

Hello Experts,

I have a webapplication where there is a form and my form has

Product Code:
      <input type="text" name="txtVpPrdCd" maxlength="15" style="text-transform:uppercase;"/>




As soon as I submit the form, the value entered in the textbox clears out. Is there a way that I can retain the value like in ASP control.

Your help is much appreciated

解决方案

Basically, your ASP.NET code generates HTML with the data which is not filled in, empty data. But after the form is submitted, you got some data on your server side. Say, it can be saved in the database. You need to use this data to fill in the page. After form submission, your form is generated again from scratch in HTTP response, because this is what your form's action attribute tells the server. It requests the page in HTTP request. If this is the same page as the original one, it will be loaded again unfilled. Fill it from your data using APS.NET syntax you are using. Other detail depends on what is your data on the server side.

There also a purely client-side approach where all the data is stored in the Web storage: http://en.wikipedia.org/wiki/Web_storage[^].

You need to use only the sessionStorage object, to avoid contamination of your browser data with permanently saved data. One additional problem is: how to store one data at one single key. The solution is: you can serialize it using JSON object and deserialize back to all the form data. The sample code for the entire solution is shown and explained in my article; see this section: JavaScript Calculator. 7. Dynamic Strict Mode Switching and Web Storage.

The benefit of this client-side solution is that it is universal, does not depends on what you have on the server side. It just fills in controls from the data stored from the previous submission, no matter what that data is and how it is presented on the server side.

—SA


这篇关于像ASP控件一样保留HTML值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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