0

Hey Guys,
I have a textbox which had readonly property set to true.
This textbox is used to take LongDate as it's input from a pop up calender. When i click on the button, it gives an error
"String was not recognised as valid datetime"
But when i set the textbox's readonly property to false it works completely alright, it returns values fromthe database.
Here is the code which i used

TextBox date_search = (TextBox)Page.PreviousPage.FindControl("tbMyDate");
            DateTime dateData;
            dateData = Convert.ToDateTime(date_search.Text.Trim());
            TextBox2.Text = dateData.ToLongDateString();

Why does it work when the readonly property is set to false????

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by chithrasujith
0

First you need to check whether the value returned by 'date_search' does not contain blank value by putting break point.

Also the datetime parsing in C# is based on the local date time settings. Therefore if your local date format is dd/mm/yyyy and if you enter date in mm/dd/yyyy format then this error will be happened.

0
TextBox date_search = (TextBox)Page.PreviousPage.FindControl("TextBox1");
        DateTime dateData;
       
        if (date_search.Text!="" )
        {
           dateData =Convert.ToDateTime(date_search.Text.ToString());
           TextBox2.Text = dateData.ToLongDateString();
        }
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.