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 .
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.
You can use either
TextBox1.Enabled = false;
OR
TextBox1.Attributes.Add("readonly","readonly");
Difference is that if you make enabled= false
then you cant pass the value of the textbox
. If you need to pass the value of the textbox
then you should use read-only property of textbox
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With