Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here's the javasript I'm using:
XML
<script type="text/javascript">
function setCursorPosition(elem, pos) {

        if (elem != null) {
            if (elem.createTextRange) {
                var range = elem.createTextRange();
                range.move('character', caretPos);
                range.select();
            }
            else {
                if (elem.selectionStart) {
                    elem.focus();
                    elem.setSelectionRange(caretPos, caretPos);
                }
                else
                    elem.focus();
            }
        }
    }
</script>


Here's the code on the button that will trigger the viewing of data on the textbox:
<asp:Button ID="btnEdit" class="buttonsMainteUN"  runat="server" Text="Edit" 
            ToolTip="Edit user account details" PostBackUrl="~/EditUser.aspx" OnClientCilck="var elem = document.getElementById('txtLastName');
setCursorPosition(elem,elem.value.length);"/>
Posted
Comments
CodeBlack 19-Aug-13 0:40am    
For example if i have text like 'abcdefg' then on button click event cursor should come between 'f' and 'g'. is this what you want ?
timJosh 20-Aug-13 23:32pm    
No, cursor is comes after g.

1 solution

If I understand you correctly, you are looking for:
Textbox1.ScrollToCaret
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900