views:

887

answers:

2

I am working on an asp page that verifies information in a text box after the user types it in.

A “product number” is manually entered (free form). Using the after update event, I have the page post the data and lookup the product number to determine if it is valid. If not valid an error message is posted in the box, otherwise the product number and description is placed in the box (I.E X1234 becomes X1234 – RED YO-YO). This works 100% fine. My problem is that after the update the focus is lost on all the data entry items. I want the focus to be returned to the next text box so the operator can type in the next piece of needed information.

Note: So far I inserted a function that dynamically changes the “TABSTOP” numbering such that the “next” box is assigned the #1 after the validation lookup. This works on my browser (Firefox 3.05) but is does not on my IE (Thanks Bill ! ). In IE when the posting is finished the focus for some reason ends up on the “enter the URL” and hitting tab puts the focus on some control button that is no where near where I want it to be.

+1  A: 

If you are trying to do what I think you are, this should do it.

In your ASPX page:

<script type="text/javascript">
    function focusControl(ctrlId) {
        document.getElementById(ctrlId).focus();
    }
</script>

In your code-behind:

// 'ctrl' is the name of the ASP.NET TextBox that you want to receive
// focus on load.
Page.ClientScript.RegisterStartupScript(
    typeof(Page),
    "Focuser",
    "focusControl('" + ctrl.ClientID + "');",
    true);
Sean Bright
+1  A: 

Here is the general solution:

http://couldbedone.blogspot.com/2007/08/restoring-lost-focus-in-update-panel.html

davogones