在WebForm中有2个 TextBox(TextBox6、TextBox7) ,1个Label (Label1)
2个TextBox 值为日期,从JS的canlender获得,
在Page_Load中添加了
TextBox7.TextChanged+=new EventHandler(TextBox7_TextChanged);
但不能触发该事件,需要在TextBox7按一下回车才可以!!
计算两个日期相关的天数,将该天数赋值给Label ,
请教各位老师,如何操作?!!
部分代码如下:
<td class="style5" valign="bottom">
                                请假时间:自
                                <asp:TextBox ID="TextBox6" runat="server"  onfocus="setday(this);" 
                                    Width="111px" Height="22px" AutoPostBack="true"></asp:TextBox>
                                <span class="canlender" onclick="CalendarOnClick('<%=TextBox6.ClientID %>')">&nbsp;&nbsp;&nbsp; 
                                &nbsp; </span>
                                至<asp:TextBox ID="TextBox7" runat="server" onfocus="setday(this);" AutoPostBack="True"></asp:TextBox>
                                <span class="canlender" onclick="CalendarOnClick('<%=TextBox7.ClientID %>')">&nbsp;&nbsp;&nbsp; 
                                &nbsp; </span>
                                共<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                                天</td>
        protected void TextBox7_TextChanged(object sender, EventArgs e)
        {
            DateTime d1 =Convert.ToDateTime(TextBox6.Text);
            DateTime d2 = Convert.ToDateTime(TextBox7.Text);
            TimeSpan ts = d2 - d1;
            string aa = ts.TotalDays.ToString();
            Label1.Text = aa;
        }

解决方案 »

  1.   

    首先要选中TextBox7,然后在文本框里随便输入什么.就算Changed了.
    这样才能触发事件...
      

  2.   

    你想在 什么时候触发?
    标题别写什么asp.net触发
    没一点目标性
      

  3.   

    可能是因为TextBox7用了onfocus事件,无法触发TextChanged,咋整,哪位老师指点一下
      

  4.   

    不是…是要把AutoPostBack属性设置为True……同样……会导致眼晕……
      

  5.   

    回楼上AutoPostBack属性已设置为True
      

  6.   

    饿= =TextChange事件是改变以后失去焦点才触发的吧……
      

  7.   

    有些没弄明白   楼主是要找
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {    }
    实践么?
      

  8.   

    <asp:TextBox ID="TextBox7" runat="server" onfocus="setday(this.id);" AutoPostBack="True"></asp:TextBox>
      

  9.   

    刚才又GOOGLE了一下啊,还没有找到方法我的TextBox6、TextBox7是JS赋值的两个日期想用TextBox7_TextChanged事件计算两个日期之间的天数,并且赋值给Lable1,但TextBox7失去焦点后,不能触发TextBox7_TextChanged事件,在TextBox7内按一下回车则可以。咋整呢?!!!
      

  10.   

    [code=C#]/<script type="text/javascript">
    var labelID="<%=lbl.ClientID%>";
    function ChangeLabelText()
    {   //失去焦点后触发的代码
    }
    <asp:TextBox ID="txt" runat="server" onblur="javascript:ChangeLabelText();"></asp:TextBox>
    [code]
      

  11.   

    请问lisweden老师能否能写一下计算日期天数及赋值的JS,新手,呵呵,不好意思 DateTime d1 =Convert.ToDateTime(TextBox6.Text);
      DateTime d2 = Convert.ToDateTime(TextBox7.Text);
      TimeSpan ts = d2 - d1;
      string aa = ts.TotalDays.ToString();
      Label1.Text = aa;
      

  12.   

    AutoPostBack="True"
    而且文本框失去焦点的时候才可以触发