I have two dropdownlists, and two txtboxes which have a calendar popup extender, whenever I choose an item different thant the first item , this code should populate texbox to current dates, My dropdownlists have an austoposbabk property selected, and are inside an update panel, when I choose and item it resets both textboxes instead to only the one that is on the SelectedIndexChanged
For example I need only to set the default date to the label that is inside the dropdownlist selectedIndexChanged
txtScanner_SelectedIndexChanged
will only set txtscanDate field to current date,,,
and is setting the date in the textbox on both .
Thanks for your help. Sorry my english is not very good.
<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>
<td style="width: 306px">
<label for="recordtype">Scanner:</label>
<asp:DropDownList ID="txtScanner" runat="server" CssClass="padding-input"
AutoPostBack="True" onselectedindexchanged="txtScanner_SelectedIndexChanged">
<asp:ListItem Text="-Select-" Value=''>-Select-</asp:ListItem>
<asp:ListItem>Bueno, Nancy</asp:ListItem>
</asp:DropDownList>
<label for="recordtype">Date:</label>
<br />
<asp:TextBox ID="txtScanDate" runat="server" Enabled="False" ReadOnly="True"></asp:TextBox>
<asp:CalendarExtender ID="txtScanDate_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtScanDate" Format="MM/dd/yyyy">
</asp:CalendarExtender>
protected void txtScanner_SelectedIndexChanged(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (txtScanner.SelectedItem.Text != null)
{
txtScanDate.Enabled = true;
txtScanDate.ReadOnly = false;
txtScanDate.Text = DateTime.Today.ToString("MM/dd/yyy");
}
else
{
txtScanDate.Enabled = false;
txtScanDate.ReadOnly = true;
}
}
}
protected void txtPreppin_SelectedIndexChanged(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (txtPreppin.SelectedItem.Text != null)
{
txtprepDate.Enabled = true;
txtprepDate.ReadOnly = false;
txtprepDate.Text = DateTime.Today.ToString("MM/dd/yyy");
}
else
{
txtprepDate.Enabled = false;
txtprepDate.ReadOnly = true;
}
}
}
I found my problem, I had the ViewState enabled = false on the master page, It was hard for me to find this, because my inherited page didnt show it disabled, but this was causing the problems with the textbox loosing the values on postback.Thanks