只读文本框值不能保存到我的数据库 [英] READ ONLY textbox VALUES NOT SAVING to MY DATABASE

查看:57
本文介绍了只读文本框值不能保存到我的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的代码大师,



欢乐的一天给大家,我正在用ASP.NET写一个人事网页表格我也在表格上有javascript来改善用户现在体验,在网络表单上我有 TextBox1设置为ReadOnly = True,TextBox2和TextBox3 。为简单起见,我们有以下内容:



Textbox2 = 3和TextBox3 = 2



当我们说:

TextBox1 = TextBox2 + TextBox3



我们应该有4,当我们保存到数据库时,我们希望看到4,3,2当我保存时不是这种情况,但如果我设置 ReadOnly = false ,应用程序将正确保存。

我的问题是 javascript ReadOnly 的原因是什么?



谢谢



我尝试过:



  document  .getElementById(' < %= TextBox1.ClientID%>')。value =  parseInt  document  .getElementById (' <%= TextBox2.ClientID%>')。value) +  parseInt  document  .getElementById(' <%= TextBox3.ClientID%>')。value); 

解决方案

保留只读字段仅用于显示目的,并将文本也放在隐藏字段中。当您更新只读文本框的值时,也会更新隐藏字段的值,并在回发中读取隐藏字段的值以获取数据。


检查此项帖子,明确解释



隐藏和只读文本框在Postback上失去价值| ASP.NET论坛 [ ^ ]

Dear Code Masters,

Happy Day to you all, I am writing a personnel web form with ASP.NET i also have javascript on the form to improve user experience now, on the web form i have TextBox1 set to ReadOnly=True, TextBox2 and TextBox3. For simplicity say we have the following :

Textbox2 = 3 and TextBox3 = 2

when we say :
TextBox1 = TextBox2 + TextBox3

we should be have 4, when we save to database we expect to see 4,3,2 that's not the case when i saved, but if i set the ReadOnly = false the application will save correctly.
my question is what is the cause of this javascript or ReadOnly ?

thank you

What I have tried:

document.getElementById('<%=TextBox1.ClientID%>').value = parseInt(document.getElementById('<%=TextBox2.ClientID%>').value) + parseInt(document.getElementById('<%=TextBox3.ClientID%>').value);

解决方案

Leave the read-only fields for display purposes only and put the text in a hidden field also. When you update the value of your read-only textbox also update the value of the hidden field too, and in your postback read the value of the hidden field to get the data.


Check this post, clearly explained

Hidden and readonly textbox loses value on Postback | The ASP.NET Forums[^]


这篇关于只读文本框值不能保存到我的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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