i have an asp,net textbox like this
我有一个这样的asp,net文本框
<asp:TextBox readonly="true" ID="txtLastService" runat="server"></asp:TextBox>
when i tried to get its value to a date variable LastService in code behind, i get this error
当我试图将它的值设置为代码后面的日期变量LastService时,我得到了这个错误
Conversion from string "" to type 'Date' is not valid.
将字符串“”转换为“Date”无效。
Exception Details: System.InvalidCastException: Conversion from string "" to type 'Date' is not valid. Source Error: Line 26: oItem.LastService = txtLastService.Text Source File: .\admin\vehicle\add.aspx.vb Line: 26
异常详细信息:系统。InvalidCastException:将字符串“”转换为“Date”无效。源错误:第26行:oItem。LastService = txtLastService。源文件:文本。\ admin \汽车\ add.aspx。vb:26
i have used this same code in other pages, and it works fine, except for this page any help
我已经在其他页面中使用了相同的代码,并且它工作得很好,除了这个页面有任何帮助
EDIt
编辑
Please note that the value of the textbox is not empty when i click submit on the form. And also when i remove the readonly attributes, i don;t get the error. But i need this textbox to be readonly since am using javascript to select date and setting its value
请注意,当我单击表单上的submit时,文本框的值不是空的。而且,当我删除readonly属性时,也不会得到错误。但是我需要这个文本框进行只读,因为我使用javascript选择日期并设置它的值
4 个解决方案
#1
1
Instead of Readonly="true"
, try using Enabled="false"
而不是Readonly="true",尝试使用Enabled="false"
#2
1
The error seems extremely self-explanatory to me. The string is "" and you are trying to convert it to a Date. So how the heck can an empty string be converted to a Date? What date would that be?
这个错误对我来说似乎是不言自明的。该字符串是“”,您试图将其转换为日期。那么,如何将空字符串转换为日期呢?那是几号?
#3
0
Why not use a HiddenField
instead?
为什么不使用隐藏字段呢?
<asp:hiddenfield id="txtLastService" runat="server"/>
#4
0
Try using Request.Form[txtLastService.UniqueID] if C# and Request.Form(txtLastService.UniqueID) if vb.net
试着用Request.Form[txtLastService。如果是c#和request。form (txtLastService.UniqueID)如果是vb.net的话
#1
1
Instead of Readonly="true"
, try using Enabled="false"
而不是Readonly="true",尝试使用Enabled="false"
#2
1
The error seems extremely self-explanatory to me. The string is "" and you are trying to convert it to a Date. So how the heck can an empty string be converted to a Date? What date would that be?
这个错误对我来说似乎是不言自明的。该字符串是“”,您试图将其转换为日期。那么,如何将空字符串转换为日期呢?那是几号?
#3
0
Why not use a HiddenField
instead?
为什么不使用隐藏字段呢?
<asp:hiddenfield id="txtLastService" runat="server"/>
#4
0
Try using Request.Form[txtLastService.UniqueID] if C# and Request.Form(txtLastService.UniqueID) if vb.net
试着用Request.Form[txtLastService。如果是c#和request。form (txtLastService.UniqueID)如果是vb.net的话