Google Brother Up

2009/02/04

Readonly Textbox - Error Solve - sans Javascript

How to Solve: -
1) Error in getting the value of a read only textbox in asp.net.
2) Create a readonly textbox without using Javascript.

1) When u add a text box as: -

{asp:TextBox ID="txtDate" runat="server" ValidationGroup="Submit" ReadOnly="true" Text="" TabIndex="2" /}

2) and try to get the value of the textbox in code behind as: -

objPressReleaseBO.Date = Convert.ToDateTime(txtDate.Text);

then

Error Occurs: String was not recognized as a valid DateTime.

as

the value Text of the text box cannot be read by the asp.net control

Solution:

1) take an html textbox {input runat="server" type="text" name="txtDate" id="txtDate" value="txtDate" tabindex="2" readonly /}

2) capture the value of the textbox from code behind as


objPressReleaseBO.Date = Convert.ToDateTime(txtDate.Value);

Solved: - 

1) Then the text box becomes read only
2) Also the value of the textbox is possible to capture from code behind.

179 unique visitors

No comments:

Drop Down List

1. http://www.janetsystems.co.uk/Articles/NetArticles/tabid/74/itemid/161/modid/449/Default.aspx