Tetbox 值未更新?
我有一个已禁用的 asp.net 文本框,我正在使用 JQuery 在客户端设置文本框的值。
$('[id$=txtCity]').val('Naperville');
但问题是当我尝试保存数据时。如果我说 txtCity.Text 它不会给我在客户端设置的值。
文本框被禁用,在使用 JQuery 设置值后,我看到客户端文本框中反映的值。但我不确定为什么它没有反映在服务器端。
我发现 disabled 的 TextBox 将不会在回发时随表单一起提交。如果这是真的,我如何提交这些值并在服务器端的代码中获取它。
请帮忙。感谢并感谢您的反馈。
I have an asp.net textbox which is disabled and I am setting the value for the textbox on client side using JQuery.
$('[id$=txtCity]').val('Naperville');
But the problem is when I am trying to save the data. If I say txtCity.Text it is not giving me the value that I set in the client side.
The textbox is disabled and I am seeing the value reflected in the textbox on the client side after the value is set using JQuery. But I am not sure why it is not reflected on the server side.
I found that TextBox with disabled will not be submitted with the form on postback. If that is true, how can I submit those values and get that on server side in the code behind.
Please help. Thanks and appreciate your feedback.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终可以在发布之前“取消禁用”该字段。例如,
当然,根据 Knix 的回答,使用只读字段也可能是一个可行的解决方案。
Edit: just read your comment on Knix's answer, so it sounds like dynamically removing the disabled attribute before posting may be the way to go.
You can always "un-disable" the field before posting. E.g.,
And of course using
readonly
fields, as per Knix's answer, may be a viable solution as well.Edit: just read your comment on Knix's answer, so it sounds like dynamically removing the disabled attribute before posting may be the way to go.
我认为禁用的字段不会被发布。
也许您应该尝试
readonly
字段:http://www.w3schools.com /tags/att_input_readonly.asp您始终可以使用 CSS 使只读字段显示为禁用 =)
编辑:
好的..如果您无法执行只读,那么如何使用 AJAX 来发布并直接传递数据,因为你说你可以在客户端访问它:
EDIT2:
填充隐藏字段并在服务器端使用该值怎么样,因为你不能使用只读字段或使用 AJAX?
由于此字段是隐藏的,因此用户不会知道其中的区别 =)
EDIT3:
OP 使用正确的服务器端语法来处理只读输入:
I don't think disabled fields will get posted.
Maybe you should try
readonly
field: http://www.w3schools.com/tags/att_input_readonly.aspYou can always use CSS to make the readonly field appear disabled =)
EDIT:
Ok..if you cannot do the readonly, how about using AJAX to post and directly passing over the data since you say you can access it on the client side:
EDIT2:
How about populating a hidden field and using that value on the server-side since you cannot use readonly fields or use AJAX?
Since this field is hidden, the user would not know the difference =)
EDIT3:
OP got this to work using correct server-side syntax for the readonly inputs: