简体   繁体   English

从javascript更改文本后,TextChanged事件未针对文本框触发

[英]TextChanged event not firing for text box, when the text is changed from javascript

I have a text box which im 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 :- 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 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 im calling this method inside txtDate_TextChanged method but the event is not firing as the text is changed inside the textbox. 请帮助我,我如何通过在txtDate_TextChanged方法中调用此方法来实现此目的,但是由于文本在文本框中更改,因此事件未触发。

Please suggest how I can achieve this or give me an alternate idea to fulfill my requirement. 请提出如何实现这一目标或给我一个替代想法以满足我的要求。

you have to change the AutoPostBack property of the textbox to true. 您必须将文本框的AutoPostBack属性更改为true。

Hope this may helps you. 希望这对您有帮助。

我已经修复了该问题,因为我的文本框位于ajax更新面板中,这就是事件未触发的原因。我在该文本框的更新面板中添加了一个触发器,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM