在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 %>')">
</span>
至<asp:TextBox ID="TextBox7" runat="server" onfocus="setday(this);" AutoPostBack="True"></asp:TextBox>
<span class="canlender" onclick="CalendarOnClick('<%=TextBox7.ClientID %>')">
</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;
}
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 %>')">
</span>
至<asp:TextBox ID="TextBox7" runat="server" onfocus="setday(this);" AutoPostBack="True"></asp:TextBox>
<span class="canlender" onclick="CalendarOnClick('<%=TextBox7.ClientID %>')">
</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;
}
这样才能触发事件...
标题别写什么asp.net触发
没一点目标性
protected void TextBox1_TextChanged(object sender, EventArgs e)
{ }
实践么?
var labelID="<%=lbl.ClientID%>";
function ChangeLabelText()
{ //失去焦点后触发的代码
}
<asp:TextBox ID="txt" runat="server" onblur="javascript:ChangeLabelText();"></asp:TextBox>
[code]
DateTime d2 = Convert.ToDateTime(TextBox7.Text);
TimeSpan ts = d2 - d1;
string aa = ts.TotalDays.ToString();
Label1.Text = aa;
而且文本框失去焦点的时候才可以触发