C# 当文本从javascript更改时,文本框未触发TextChanged事件
我有一个文本框,我正在从日历扩展器填充日期,代码如下:-C# 当文本从javascript更改时,文本框未触发TextChanged事件,c#,asp.net,C#,Asp.net,我有一个文本框,我正在从日历扩展器填充日期,代码如下:- <label for="input-one" class="float"><strong>Date</strong></label><br /> <asp:TextBox ID="txtDate" runat="server" CssClass="inp-text" Enabled="false" AutoPostBack="true"
<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 />
我的要求是,当在文本框中输入日期时,我想调用此方法:
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;
}
}
public void timespontdisplay()
{
字符串日期=txtDate.Text.ToString();
DateTime dateparsed=DateTime.ParseExact(日期,“dddd,MMMM dd,yyyy”,空);
DateTime currentDate=System.DateTime.Now;
如果(dateparsed.Date>currentDate.Date)
{
divtimespunt.Visible=true;
}
if(dateparsed.Date
当我在txtDate\u TextChanged
方法中调用此方法时,请帮助我如何实现这一点,但当文本在文本框中更改时,事件不会触发
请建议我如何实现这一点,或者给我一个替代方案来满足我的要求。您必须将文本框的AutoPostBack属性更改为true
希望这能对您有所帮助。我已经修复了它,因为我发现文本框位于ajax更新面板中,这就是事件未触发的原因。我在更新面板中为该文本框添加了一个触发器,它工作正常。我这样做了,但txtDate\U TextChanged事件仍然没有触发。您可以在代码中看到它也被设置为true。请检查这是您的事件工作,只需在文本框中写入文本。不,它不工作,我启用了文本框,并手动更改了文本框文本,但未触发事件。请添加您尝试过的内容。这会更有帮助。
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;
}
}