无法获得与文本框中的文本时,它是只读的? [英] Can't get text with text box when it is readonly?

查看:133
本文介绍了无法获得与文本框中的文本时,它是只读的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框

<asp:textbox runat="server" id="checkIn" ClientIDMode="Static" ReadOnly="true">
</asp:textbox>

在文本框中的文本是通过一个jQuery的DatePicker输入。在一些code后面我正在从这个文本框中的文本像这样。

The text in the text box is inputted through a Jquery DatePicker. In some code behind I am getting the text from this text box like so.

string x=checkIn.Text;

为什么我不能拉​​从文本框中输入的日期?我猜测它是与事实,即它是只读的,当我删除此它的工作原理呢?

Why can I not pull the inputted date from the text box? I am guessing it is to do with the fact that it is readonly as when I remove this it works?

谁能帮我?

推荐答案

在ASP.Net,如果只读值发生改变,它会恢复到上回发的原始值。

In ASP.Net, if the readonly value is changed, it will revert to the original value on the postback.

但是,您可以使用wrokaround,而不是指定只读声明,将其指定为在code隐藏的属性。即。

You can use a wrokaround however, instead of specifying readonly declaratively, assign it as an attribute in code-behind. i.e.

而不是

&LT; ASP:文本=服务器ID =签入只读=真...

应用此为code-背后

apply this is code-behind

checkIn.Attributes.Add(只读,只读);

不过,视图状态仍然可能不适合该工作。

But, the viewstate still may not work with this.

更多信息:

之间的细微差别只读禁用在HTML控件。在禁用的将不能与表单提交,但是只读的会。从字面上看,只读只是只读的,但禁用其实就是禁用

There is a subtle difference between readonly and disabled controls in HTML. The disabled ones will not be submitted with the form, however the readonly ones will. Literally, readonly is just readonly, but disabled is actually disabled.

从W3C:<一href=\"http://www.w3.org/TR/html401/interact/forms.html#h-17.12\">http://www.w3.org/TR/html401/interact/forms.html#h-17.12

在17.13表单提交趴下第17.13.2成功控制的)

如果控制声明一样,即如果该属性初始化过程中设置ASP.Net然而,恢复到上回发原始值。这也就是为什么后来设置属性(在页面加载)不会影响此行为。

ASP.Net however, reverts to the original value on postback if a control is declared like that i.e. if the attribute is set during init. Which is why setting the attribute later (in page load) will not affect this behavior.

这篇关于无法获得与文本框中的文本时,它是只读的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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