Change Textbox Value on Selected Index Changed DDL not working


I need to make a texbox visible only when a selection is not null, (first selection), and then enable a texbox that gets populated with the current date, (user can change the date) I am using an update panel and setting up the autopostback property to true on the dropdown list, the problem is that the texbox is taking the selection on date when I insert to table....

can you please suggest what to do?


<td style="width: 286px">
                <label for="recordtype">
                    ID="txtPreppin" runat="server" CssClass="padding-input" 
                    AutoPostBack="True" onselectedindexchanged="txtPreppin_SelectedIndexChanged">
                    <asp:ListItem Text="-Select-" Value=''>-Select-</asp:ListItem>
                    <asp:ListItem>Acevedo, Noe</asp:ListItem>
                <br />
                <label for="recordtype">
<asp:TextBox ID="txtprepDate" runat="server" 
                    Enabled="False" ReadOnly="True"></asp:TextBox>
                <asp:CalendarExtender ID="txtprepDate_CalendarExtender" runat="server" 
                    Enabled="True" TargetControlID="txtprepDate" Format="MM/dd/yyyy">

   protected void txtPreppin_SelectedIndexChanged(object sender, EventArgs e)

         if (Page.IsPostBack)

             txtprepDate.Text = DateTime.Today.ToString("MM/dd/yyy");
             txtScanDate.Text = DateTime.Today.ToString("MM/dd/yyy");

             if (txtPreppin.SelectedItem.Text != null)
                 txtprepDate.Enabled = true;
                 txtprepDate.ReadOnly = false;

                 txtprepDate.Enabled = false;
                 txtprepDate.ReadOnly = true;

Open in new window

Who is Participating?
Lalit ChandraConnect With a Mentor Commented:
This task can be done at the client side (on browser itself),so no need to do a round-trip to the server for this small task.
Simple, put the jquery link on your page and use the following code to achieve the same

$(function() {
      $("#txtbox").css("display","none");  // Hide the textbox on first page Load.

    $("#ddsListName").change(function() {
         if($(this).value != "0") // For the first element

Now in code behind,simple in the Page_Load event assign the textbox with current date.

That's done.
TonyRebaAuthor Commented:
Could I change the property to enabled and read only false instead of hidding it?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.