TextBox KeyDown事件 [英] TextBox KeyDown event

查看:263
本文介绍了TextBox KeyDown事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp文本框创建一个用户控件。要添加KeyDown和KeyUp事件,我使用下面的代码。当用户在文本框中键入一些文本时,列表框将被过滤并显示列表。它的工作完美。但如果我在我的页面中使用的不仅仅是用户控件,当我输入一个控件时,所有控件列表框都会显示。我该如何防止这种情况?

I am creating an user control with asp textbox .To add the KeyDown And KeyUp Event I am using the below code.When User typing some text in the text box the listbox is filtered and show the list. Its working Perfect .But if I am using more than user controls in my page,when i type in one control all controls list boxes are showing. How can i prevent this?

<asp:TextBox ID="txtBox" runat="server" onkeydown="onTxtKeyDown();"  onkeyup="onTxtKeyUp();"  >

 <asp:Button runat="server" ID="btnSearch" Style="display: none" OnClick="HandleAjaxCall"/>
      <asp:Label runat="server" ID="lblStatus" />

 protected void HandleAjaxCall(object sender, EventArgs e)
        {
            BindDataToListView(txtBox.Text);           
        }

 <script type="text/javascript">
     var to; // variable to which we assign setTimeout function
     var prm = Sys.WebForms.PageRequestManager.getInstance(); // Page Request Manager object
     function onTxtKeyUp() {
         to = setTimeout('performSearch();', 300);
     }
     function onTxtKeyDown() {
         if (to) clearTimeout(to);
     }
     function performSearch() {
         if (prm.get_isInAsyncPostBack) {
             prm.abortPostBack();
         }
         $get("<%=lblStatus.ClientID %>").innerHTML = "Loading...";
         __doPostBack("<%=btnSearch.UniqueID %>", "");
     }
</script>

推荐答案

get( <%= lblStatus.ClientID%>)。innerHTML = 正在加载......;
__doPostBack( <%= btnSearch.UniqueID%> );
}
< / 脚本 >
get("<%=lblStatus.ClientID %>").innerHTML = "Loading..."; __doPostBack("<%=btnSearch.UniqueID %>", ""); } </script>


onKeyUp javascript事件有什么问题?

What is wrong with the onKeyUp javascript event?
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <script type="text/javascript">
        function KeyReleased() {
            // Do what you want
            // Example:
            var a = document.getElementById("TextBox1").value;
            document.getElementById("divResult").innerHTML = a;
            return true;
        }
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:TextBox ID="TextBox1" onKeyUp="KeyReleased()" runat="server"></asp:TextBox>
        <div id="divResult"></div>
    </div>
    </form>
</body>
</html>


这篇关于TextBox KeyDown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆