Question

i have an asp,net textbox like this

<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

Conversion from string "" to type 'Date' is not valid.

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

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

Was it helpful?

Solution

Instead of Readonly="true", try using Enabled="false"

OTHER TIPS

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?

Why not use a HiddenField instead?

<asp:hiddenfield id="txtLastService" runat="server"/>

Try using Request.Form[txtLastService.UniqueID] if C# and Request.Form(txtLastService.UniqueID) if vb.net

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top