Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a text box which i m filling of date from the calendar extendar and the code is as below:-
ASP.NET
<label for="input-one" class="float">Date</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 :-
JavaScript
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 the below method.
C#
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 me that how i achieve this or give me an alternate idea to fulfill my requirement.
Posted
Updated 25-Jun-12 0:59am
v2

Try writing Javascript function in onChange event of the textbox and achieve the same functionality.
 
Share this answer
 
I had fixed it as i the text box is inside an ajax update panel and that's why the event is not firing.I had added a trigger in the update panel for that text box and it worked fine.

ASP.NET
<triggers>
        <asp:asyncpostbacktrigger controlid="txtDate" eventname="TextChanged" xmlns:asp="#unknown" />
        </triggers>
 
Share this answer
 
You can also try making call to method using JQuery or ClientCallback which processes effectively and this also improve performance, since the entire ajenda is to make async call
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900