I've creating one ASP web application, in that application one form have to update date value in the textbox field i put calender button near that textbox. it can update the date in that textbox field but its editable . i want update date value through only using calender button , i used read-only property but return empty value so not works .
6 Answers
Try client side html readonly attribute instead of ASP.NET server side readonly.
myTextBox.Attributes.Add("readonly", "readonly");
From MSDN,
The Text value of a TextBox control with the ReadOnly property set to true is sent to the server when a postback occurs, but the server does no processing for a read-only text box. This prevents a malicious user from changing a Text value that is read-only. The value of the Text property is preserved in the view state between postbacks unless modified by server-side code.
This is why textbox with server side readonly attribute has null value in postback.
Comments
On page load event of your code behind file just write following code:
yourTextBoxName.Attributes.Add("readonly","readonly");
you can also do same by using property
Enabled="false"
on your aspx page but then you will not be able access its value in code behind page.
1 Comment
You can make textBox non-editable in asp.net