Retain TextBox focus on AJAX Timer Tick event in ASP.Net

Last Reply 7 months ago By dharmendr

Posted 7 months ago

i have gridview inside update panel and textbox is outside update panel.at timer tick event i m updating data of gridview.my update panel updatemode=conditional.problem is that at timer tick event when gridview reload , then cursor moves out from textbox.

sir my timer tick event working properly,but there is textbox in which i type something,and after clcik on save button that text go to save in database.

problem is that if i m typing something in textbox and in between timer tick event occure, then cursor moves out from textbox,i need to again click inside textbox to type somethting.

i need if i m typing in textbox,if timer tick event occure, then my cursor will not move out from textbox or if it will always moves out then how to cursor moves in textbox at that position again on timer tick event.

Posted 7 months ago

In Timer Tick event you can set focus to the TextBox of your choice.

There is nothing much which can be done for such case.

txtDate.Focus();

 


Posted 7 months ago

sir if i do this then problem is that cursor always comes to start position not there where my text ends that time when timer tick event occure.


Posted 7 months ago Modified on 7 months ago

For that you have to use JavaScript to place cursor at end of text in TextBox.

Javascript

<script type="text/javascript">
    function SetFocusAtEnd(txt) {
        var length = txt.value.length;
        txt.setSelectionRange(length, length);
    }   
</script>

Call the JavaScript function on onfocus event of TextBox.