I have a simple CalendarExtender (from AjaxControlToolkit) attached to a textbox.
<asp:TextBox ID="StartDateText" runat="server" MaxLength="10" Width="70px" AutoPostBack="True" OnTextChanged="StartDateText_TextChanged" />
<asp:ImageButton ID="ImageCalendarStartDate" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" AlternateText="Click to show calendar" />
<asp:CalendarExtender ID="StartDateCalendarExtender" runat="server" TargetControlID="StartDateText" PopupButtonID="ImageCalendarStartDate" />
In order to control user input, I have the AutoPostBack
set to True
on the textbox, as well as a function on the TextChanged
event (although TextChanged
isn't the issue here).
In Page_Load
, I have:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
StartDateCalendarExtender.SelectedDate = DateTime.Now.AddDays(-1);
}
}
On opening the page, Page_Load
sets the date, but the AutoPostBack triggers a postback right after Page_Load
, calling it again with IsPostBack
set to true.
Is there a server-side way to prevent this postback?
I tried setting the AutoPostBack
property to false, changing the SelectedDate
, and setting it back to true, but it keeps firing a postback.