Search code examples
asp.nettextboxcompiler-errorsreadonly-attribute

cant get the value of a readonly textbox in asp.net


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


Solution

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