Link to home
Start Free TrialLog in
Avatar of TonyReba
TonyRebaFlag for United States of America

asked on

Change Textbox Value on Selected Index Changed DDL not working

HI EE

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?

Thanks

<td style="width: 286px">
                <label for="recordtype">
                                 *Prepper:</label><asp:DropDownList 
                    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>
                </asp:DropDownList>
                <br />
                <label for="recordtype">
                                 *Date:</label>
<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">
                </asp:CalendarExtender>
               
                
               
        </td>

   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;
                                  
             }

             else
             {
                 txtprepDate.Enabled = false;
                 txtprepDate.ReadOnly = true;
             }
         }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lalit Chandra
Lalit Chandra
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TonyReba

ASKER

Could I change the property to enabled and read only false instead of hidding it?