Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

set focus to end of text box in update panel postback not working in FF & Chrome

$
0
0

My solution is working fine in IE but not in FF & Chrome browsers. Please give suggestions/solution  to implement the functionality that works for all browsers. I am using the text box to search a grid view on keyup.

Javascript Code:

<script type="text/javascript">

        var tbPostBackTimeout = null;

        function onTextBoxChanging(sender) {
            clearTimeout(tbPostBackTimeout);

            tbPostBackTimeout = setTimeout(function () {
                __doPostBack(sender.name, '');
            }, 500);
        }

        function setFocustxt() {
            var currentCaret;
            function getCaret(textbox) {
                var textbox = $get("<%=txtSearch.ClientID%>");
                var control = document.activeElement;
                textbox.focus();
                var rang = document.selection.createRange();
                rang.setEndPoint("StartToStart", textbox.createTextRange());
                return rang.text.length;
            }


            function setfocus() {
                var txb = $get("<%=txtSearch.ClientID%>");
                var t = txb.createTextRange();
                t.collapse(true);

                t.moveStart("character", currentCaret);
                t.select();

            }

            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(
            function (sender, e) {
                currentCaret = getCaret($get("<%=txtSearch.ClientID%>"));

            });
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
            function (sender, e) {

                setfocus();
            });

        }

</script>

ASP.net code in update panel.

<asp:TextBox ID="txtSearch" runat="server" Width="171px" AutoPostBack="True" OnTextChanged="txtSearch_TextChanged"
            onkeyup="onTextBoxChanging(this);"  onfocus="setFocustxt();"  ></asp:TextBox>

 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>