如何使ASP.NET文本框消防它onTextChanged事件火在AJAX的UpdatePanel?文本框、事件、ASP、NET

由网友(一袭白纱却旁无少年??)分享简介:我试图让一个文本框火它的每一次击键作出,而不是只有射击,只有当它失去集中时间onTextChanged事件。我认为,加入AsyncPostBackTrigger会做到这一点,但它仍然没有工作。是我尝试做甚至有可能是什么?在code是如下:<%@页面语言=C#AutoEventWireup =真正的codeBehi...

我试图让一个文本框火它的每一次击键作出,而不是只有射击,只有当它失去集中时间onTextChanged事件。我认为,加入AsyncPostBackTrigger会做到这一点,但它仍然没有工作。是我尝试做甚至有可能是什么?在code是如下:

 <%@页面语言=C#AutoEventWireup =真正的codeBehind =Items.aspx.cs的MasterPageFile =〜/ MMPAdmin.Master继承= MMPAdmin.Items%>
< ASP:内容ID =内容1=服务器ContentPlaceHolderID =ContentPlaceHolder1>
< ASP:ScriptManager的ID =sm_Main=服务器/>
    < D​​IV的风格=左:10px的;位置:亲属;宽度:100%;溢出:隐藏>
        < ASP:UpdatePanel的ID =up_SearchText=服务器>
            <触发器>
                 < ASP:AsyncPostBackTrigger控件ID =tb_Search事件名称=框TextChanged/>
            < /触发器>
            <的ContentTemplate>
                < D​​IV的风格=的位置:亲属;浮动:左>
                    < B风格=字体大小:XX-大>项目< / B>(< A HREF =Item.aspx>添加全新< / A>)
                < / DIV>
                < D​​IV的风格=右:25像素;位置:绝对的;顶部:30PX>
                    搜索:LT; ASP:文本框ID =tb_Search=服务器WIDTH =200OnTextChanged =UpdateGrid的AutoPostBack =真/>
                < / DIV>
                < BR />
                < D​​IV>
                    < ASP:GridView控件=服务器的AutoGenerateColumns =真正的ID =gv_ItemsAutoGenerateEditButton属性=真正的AutoGenerateDeleteButton =真/>
                < / DIV>
            < /的ContentTemplate>
        < / ASP:UpdatePanel的>
    < / DIV>
< / ASP:内容>
 

解决方案 您需要调用 _postback()功能,为您的文本框控件,当的onkeyup 是使用JavaScript提高。 然而,由于你的文本框为您更新面板内,该文本框将得到重新渲染每当用户点击一个键,使光标宽松的焦点。 除非你得到你的文本框出在UpdatePanel这将无法使用。这可能制定出适合你,作为更新面板往往是有点慢,你可能仍然可用性问题。 - 我会建议使用自动完成组件

PS :有一个在asp.net控件工具包或者你可以使用jQuery的自动完成插件,我发现是一个好一点

I am trying to get an textBox to fire it's onTextChanged event every time a keystroke is made rather than only firing only when it looses focus. I thought that adding the AsyncPostBackTrigger would do this but it's still not working. Is what I'm trying to do even possible? The code is below:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Items.aspx.cs" MasterPageFile="~/MMPAdmin.Master" Inherits="MMPAdmin.Items" %>
<asp:Content ID="content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:ScriptManager ID="sm_Main" runat="server" />
    <div style="left:10px;position:relative;width:100%;overflow:hidden">
        <asp:UpdatePanel ID="up_SearchText" runat="server">
            <Triggers>
                 <asp:AsyncPostBackTrigger ControlID="tb_Search" EventName="TextChanged" />
            </Triggers>
            <ContentTemplate>
                <div style="position:relative;float:left">
                    <b style="font-size:xx-large">Items</b>(<a href="Item.aspx">Add New</a>)
                </div>
                <div style="right:25px;position:absolute; top:30px">
                    Search: <asp:TextBox ID="tb_Search" runat="server" Width="200" OnTextChanged="UpdateGrid" AutoPostBack="true" />
                </div>
                <br />
                <div>
                    <asp:GridView runat="server" AutoGenerateColumns="true" ID="gv_Items" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" />
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>
Vision如何使用文本框

解决方案

You need to call the _postback() function for your textbox control when the onkeyup is raised using javascript. However, since your textbox is inside your update panel, the textbox will get re-rendered everytime the user hits a key, causing the cursor to loose focus. This will not be usable unless you get your textbox out of the the updatepanel. That may work out for you, as update panels tend to be a bit slow, you may still have usability issues. - I would suggest using an autocomplete component.

P.S : there is one in the asp.net control toolkit or you could use the jquery autocomplete plugin which I have found to be a bit better.

阅读全文

相关推荐

最新文章