神秘的TextBox失去焦点 [英] TextBox mysteriously losing focus

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

问题描述

所以我有这样的UpdatePanel中有这个文本框。每当我点击它,它着重然后失去焦点在不到一秒钟。因此,人们似乎无法写的文本框内任何东西。我该怎么解决这个问题呢?

 < ASP:内容ID =Content3ContentPlaceHolderID =日程地址搜索Maincontent=服务器>
< ASP:的UpdatePanel =服务器ChildrenAsTriggers =真>
    <&的ContentTemplate GT;
        < ASP:定时器=服务器ID =updateTimer间隔=1000OnTick =updateTimer_Tick>< / ASP:定时器>
        < D​​IV>
            < ASP:面板=服务器BORDERCOLOR =黑色边框=双边框宽度=4滚动条=垂直>
                < ASP:文字=服务器ID =chatLabel>< / ASP:文字>
            < / ASP:面板>
            < ASP:文本框=服务器ID =chatTextBox的ClientIDMode =静态边框=双BORDERCOLOR =黑色边框宽度=4的AutoPostBack =真正的安其preSS =返回EnterEvent(事件)>< / ASP:文本框>
            < ASP:按钮=服务器ID =chatSubmit的OnClick =chatSubmit_Click文本=发送/>
        < / DIV>
    < /&的ContentTemplate GT;
< / ASP:的UpdatePanel>
<脚本>
    功能EnterEvent(五)
    {
        如果(e.key code == 13)
        {
            __doPostBack('&下;%= chatSubmit.UniqueID%GT;',);
        }
    }
< / SCRIPT>
< / ASP:内容>


解决方案

这将做到这一点。重点preSS,您触发异步回发,这是什么原因造成你失去焦点。你将不得不使用JavaScript,并使用

  Sys.Application.add_endRequest(功能(发件人,E){})

要监听的请求结束,并把焦点返回。

我看你正在尝试做的,我会强烈建议使用Web服务或Signalr,做你想做的事情。你是不是会得到能力或性能,你正在寻找。更新面板占用焦点离开,因为它回发,因此用户不能只是一味地打字。更新面板是有些限制的方式。

So I have got this UpdatePanel in which there is this TextBox. Whenever I click in it, it focuses and then loses the focus in less than a second. Therefore one seem unable to write anything inside the TextBox. How do I solve this issue?

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
    <ContentTemplate>
        <asp:Timer runat="server" ID="updateTimer" Interval="1000" OnTick="updateTimer_Tick"></asp:Timer>
        <div>
            <asp:Panel runat="server" BorderColor="Black" BorderStyle="Double" BorderWidth="4" ScrollBars="Vertical">
                <asp:Literal runat="server" ID="chatLabel"></asp:Literal>
            </asp:Panel>           
            <asp:TextBox runat="server" ID="chatTextBox" ClientIDMode="Static" BorderStyle="Double" BorderColor="Black" BorderWidth="4" AutoPostBack="true" OnKeyPress="return EnterEvent(event)"></asp:TextBox>
            <asp:Button runat="server" ID="chatSubmit" OnClick="chatSubmit_Click" Text="Send"/>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
<script>
    function EnterEvent(e)
    {
        if (e.keyCode == 13)
        {
            __doPostBack('<%= chatSubmit.UniqueID %>', "");
        }
    }
</script>
</asp:Content>

解决方案

It's going to do that. On key press, you trigger an async postback, and that is what is causing you to lose the focus. you would have to use javascript, and use

Sys.Application.add_endRequest(function(sender, e) { })

To listen for the end of the request and put the focus back.

I see what you are trying to do, and I would highly recommend using a web service, or Signalr, to do what you want to do. You are not going to get the ability or performance you are looking for. An update panel takes focus away as it posts back, and so the user can't just keep typing. The update panel is somewhat restrictive that way.

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

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