Asp.net 何时调用此javascript函数?
我已经创建了一个页面,在那个页面中,我编写了一个javascript函数,用于在用户在文本框中输入内容时显示字符数Asp.net 何时调用此javascript函数?,asp.net,Asp.net,我已经创建了一个页面,在那个页面中,我编写了一个javascript函数,用于在用户在文本框中输入内容时显示字符数 protected void Page_Load(Object sender, EventArgs e) { TextBox1.Attributes.Add("onkeyup", "DisplayCharCount()"); } 首次页面加载时,文本框为空。Textbox没有autopostback==true.After pageload,用户在文本框中输入文本。此页
protected void Page_Load(Object sender, EventArgs e)
{
TextBox1.Attributes.Add("onkeyup", "DisplayCharCount()");
}
首次页面加载时,文本框为空。Textbox没有autopostback==true.After
pageload,用户在文本框中输入文本。此页面不会再次加载。因此,当调用此函数时?每次用户请求页面时,都会调用
page\u Load
方法。每当用户按下TextBox1
元素中的键(即释放键)时,就会调用DisplayCharCount
方法。Page\u Load
每次重新加载页面时都会调用该方法。因此,onkeyup
将在每次重新加载页面时绑定到文本框
何时调用此函数
当用户在TextBox1上键入时释放键时,会触发此事件
您也只能第一次绑定它:
protected void Page_Load(Object sender, EventArgs e)
{
if(!IsPostBack)
{
TextBox1.Attributes.Add("onkeyup", "DisplayCharCount()");
}
}
或者您也可以直接将其绑定为:
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" onkeyup="DisplayCharCount()">
</asp:TextBox>
为什么不能在标记中调用此脚本?