Calling server side method as filling value inside a textbox from calendar extender
- by Dharmendra Singh
I have a text box which i m filling of date from the calendar extender and the code is as below:-
<label for="input-one" class="float"><strong>Date</strong></label><br />
<asp:TextBox ID="txtDate" runat="server" CssClass="inp-text" Enabled="false" AutoPostBack="true"
Width="300px" ontextchanged="txtDate_TextChanged"></asp:TextBox>
<asp:ImageButton ID="btnDate2" runat="server" AlternateText="cal2"
ImageUrl="~/App_Themes/Images/icon_calendar.jpg" style="margin-top:auto;"
CausesValidation="false" onclick="btnDate2_Click" />
<ajaxToolkit:CalendarExtender ID="calExtender2" runat="server"
Format="dddd, MMMM dd, yyyy"
OnClientDateSelectionChanged="CheckDateEalier"
PopupButtonID="btnDate2" TargetControlID="txtDate" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="txtDate" ErrorMessage="Select a Date" Font-Bold="True"
Font-Size="X-Small" ForeColor="Red"></asp:RequiredFieldValidator><br />
Javascript code is :-
function CheckDateEalier(sender, args)
{
sender._textbox.set_Value(sender._selectedDate.format(sender._format))
}
My requirement is that as the date is entered in to the textbox, I want to call this method:
public void TimeSpentDisplay()
{
string date = txtDate.Text.ToString();
DateTime dateparsed = DateTime.ParseExact(date, "dddd, MMMM dd, yyyy", null);
DateTime currentDate = System.DateTime.Now;
if (dateparsed.Date > currentDate.Date)
{
divtimeSpent.Visible = true;
}
if (dateparsed.Date < currentDate.Date)
{
divtimeSpent.Visible = true;
}
if (dateparsed.Date == currentDate.Date)
{
divtimeSpent.Visible = false;
}
}
Please help me that how i achieve this as i m calling this method inside txtDate_TextChanged method but the event is not firing as the text is changed inside the textbox.
Please suggest how I can achieve this or give me an alternate idea to fulfill my requirement.