我用的是ajax实现的
前台:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="10" OnTick="Timer1_Tick">
</asp:Timer>
<asp:TextBox ID="TextBox1" runat="server" MaxLength="50"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label" ForeColor="Red"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
后台:
protected void Timer1_Tick(object sender,EventArgs e)
{
Label1.Text = "您还可以输入" + (50 - TextBox1.Text.ToString().Length) + "字";
}
希望可以帮助您
可以,把Label1.Text = "您还可以输入" + (50 - TextBox1.Text.ToString().Length) + "字"; 换成: Label1.Text = "您还可以输入" + (50 - System.Text.Encoding.Default.GetByteCount(TextBox1.Text.ToString())) + "字";
原文链接:https://www.f2er.com/ajax/164182.html