Knowledge base

IT is a great and exciting world to be in.
All who have passion for it will understand why we have created these pages.
Here we share our technical knowledge with you.
ProgrammingAICloudManagementMobileDB & AnalysisSafetyOtherArchitectureTips

ASPX Textbox focus issue


Libor Bešenyi (Solution architect)

We were experiencing losing focuse of ASPX textboxes embedded in Ajax update panel. jQuery helped again.

<asp:TextBox ID="TextBoxStoreys" runat="server" Width="60px" AutoPostBack="true" />

Pressing tab on this control fired server-side on change event (this is correct), but next focused element was lost.

We have implemented hidden field in general master page which keeps last fired element ID and 2 java-script routines: First stored fired control ID and second has catch ending of asynchronous request. Than find next possible element (which is focused manually).

<asp:HiddenField ID="hiddenFieldLastAutopostbackFiredElement" runat="server" />
       <script type="text/javascript">
                    function (sender, e)
                           // #6220 Save latest focus (textbox autopostback issue)
                           var inputHoldsLastFocus = getElement("hiddenFieldLastAutopostbackFiredElement");
                           if (inputHoldsLastFocus.value)
                                  var lastControl = getElement(inputHoldsLastFocus.value);

                                  // Focus next control
                                  var allPossibleElements = $('input:text');
                                  var index = allPossibleElements.index(lastControl);

                                  if (index >= 0 && index + 1 < allPossibleElements.length)
                                        var nextElement = allPossibleElements[index + 1];
                                  } // if

                                   inputHoldsLastFocus.value = null;
                           } // if

              function AutoPostBackTextBox(control)
                    // #6220 Save latest focus (textbox autopostback issue)
                    var inputHoldsLastFocus = getElement("hiddenFieldLastAutopostbackFiredElement");

                    inputHoldsLastFocus.value =;

                     __doPostBack(, "");

AutoPostback on the textbox was removed, as you can see is postback raised within the storing the last element ID:

<asp:TextBox ID="TextBoxStoreys" runat="server" Width="60px" onchange="javascript: AutoPostBackTextBox(this);" />




Find out more


Quick start

Contact us for a free consultation on your business needs!
After the discussion we will perform mapping of the processes and analyse the current state.
You will receive variety of scenarios to choose from discribing different ways how to solve your issue.
Contact us