<asp:TextBox ID="TextBox3" runat="server" ReadOnly="True" ></asp:TextBox>
 <asp:CalendarExtender ID="CalendarExtender2" TargetControlID="TextBox3"
                            runat="server">

I have use text box and calender

Dani AI

Generated

Short answer: an HTML input with readonly will be submitted with the form; a disabled input (Enabled="False") will not. So setting Enabled="False" (as suggested) makes the problem worse. If a readonly textbox value is not reaching the database, something else is dropping or overwriting the value.

Quick troubleshooting checklist:

  • Inspect the rendered HTML with browser devtools. Confirm the control has a name and value, and that it is not rendered as disabled.
  • Watch the Network tab while submitting to see the form payload. That confirms whether the value is being posted.
  • On the server, read the raw post data to verify what arrived: for example check Request.Form[myTextBox.UniqueID] during postback.
  • Look for server-side code that reassigns or databinds the TextBox on every postback (Page_Load without an IsPostBack guard). That often overwrites the posted value before the insert runs.
  • Check client-side scripts (calendar extender callbacks, validators, submit handlers) that might clear or copy values before submit.

Two common fixes that are safe and reliable:

  • Remove readonly just before submit with a small client-side routine (so the posted field is handled by the browser and picked up normally).
  • Or copy the readonly value into a hidden field just before submit and use the hidden field value for the DB insert.

Example pattern (client-side enable-before-submit):

<script type="text/javascript">
function enableForSubmit(clientId) {
  var el = document.getElementById(clientId);
  if (el) el.readOnly = false;
  return true;
}
</script>

<asp:Button ID="btnSave" runat="server" Text="Save"
    OnClientClick="return enableForSubmit('<%= TextBox3.ClientID %>');" />

Alternative: copy to a HiddenField in an OnClientClick and insert ServerSide from the HiddenField. As hinted, toggling ReadOnly client-side is a valid approach; just avoid Enabled="False" if the value must be posted.

Recommended Answers

All 2 Replies

Instead of using the ReadOnly="True" property ... how about using the Enabled="False" property?

Another option would be to fire a javascript to set the ReadOnly property to "False" after the validation of the form, but before actually submitting the form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.