ASP.NET TextBox OnTextChanged event not fire

戏子无情 提交于 2019-12-24 08:46:22

问题


I've the following problem: asp.net TextBox server side control, fire onTextChanged only when it loose focus. I would like to fire my server side event each time user press a key. How can i do ? Thanks


回答1:


<asp:TextBox runat="server" onkeyPress="MyKeyPressEvent;" ID="txtUserName" />

Just add the onkeyPress client event to your textbox.

Then in your JavaScript function "MyKeyPressEvent", call a PageMethod that fires your event method.

Pagemethods are good with onkeyPress, since they have very small Request sizes.




回答2:


Going to have to use ajax since the keypress is a client side event.




回答3:


you can use javascript and pagemethods to make it as efficient as possible

use the onkeyup to call a function where you call your pagemethod

http://www.dotnetfunda.com/articles/article454-using-pagemethods-and-json-in-aspnet-ajax.aspx - pagemethods



来源:https://stackoverflow.com/questions/2885423/asp-net-textbox-ontextchanged-event-not-fire

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!