Can not get read-only text field value 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 LastService date variable value in the code behind, I get this error

Conversion from the 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 used the same code on other pages and it works fine except for this page any help

EDIT

Please note that the value of the text field is not empty when I click the submit button on the form. And also, when I remove readonly attributes, I don't get an error. But I need this text box to be read-only, as I use javascript to select a date and set its value

+3
source share
4 answers

Instead, Readonly="true"try usingEnabled="false"

+1
source

The error seems very clear to me. The string is "" and you are trying to convert it to Date. So how can heck convert an empty string to Date? What date will be?

+1
source

HiddenField ?

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

Request.Form [txtLastService.UniqueID], # Request.Form(txtLastService.UniqueID), vb.net

0

All Articles