Asp.net asp:文本框只读
在asp文件中,我有两个asp:textboxAsp.net asp:文本框只读,asp.net,textbox,Asp.net,Textbox,在asp文件中,我有两个asp:textbox <asp:TextBox ID="textValue" runat="server" Width="100px"/> <asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true"/> 然后我通过javascript设置值 <asp:TextBox ID="textValue" runat="server" Width="100p
<asp:TextBox ID="textValue" runat="server" Width="100px"/>
<asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true"/>
然后我通过javascript设置值
<asp:TextBox ID="textValue" runat="server" Width="100px" value="aaa"/>
<asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true" value="bbb"/>
但是当刷新网页时终于得到了
<asp:TextBox ID="textValue" runat="server" Width="100px" value="aaa"/>
<asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true"/>
为什么bbb值“丢失”?如何避免这种情况?我认为,不要只读,而是将您的值设置为文本框,然后禁用它。正在回发“bbb”,但.NET不会从回发数据填充只读文本框。通过从
Page\u Load()
方法抓取表单数据,您可以手动填充文本框,如下所示:
textValue2.Text=Request.Form[textValue2.UniqueID]代码>
<asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true"/>
“true”之前缺少引号,这可能会导致问题。从文本框中删除服务器端属性-ReadOnly-并从代码中设置HTML属性。您将能够访问该值,然后返回:
textValue2.Attributes.Add("readonly","readonly");
如何使用javascript将值设置为只读文本框。一个典型的例子是日历+输入文本。