setting focus after tabbing off a textbox in an update panel

Hi,

I have a number of controls inside an update panel.

When I tab off the first which has an autopostback=true, I run some code that goes off an hits the db, then sets the value of a literal control based on the results.

The problem is when I tab off, initially the cursor goes to the next textbox, however once the db hit has finished and the value of the literal gets set, the 2nd textbox then loses focus and the cursor is no longer where it should be.

I have tried adding txtInvCP.Focus() which is the 2nd textbox, inside the function that runs on the autopostback but still no joy, hopefully there is a way around this?

Thanks in advance.
scm0smlAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Akin DeluI’m a software engineer, tech enthusiast and UI/UX lover. Commented:
some little javascript trick will do that for you.

<script type="text/javascript">
function RegisterEvent()
{
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
function endRequestHandler(sender, args)
{
    document.getElementById("<%= txtInvCP.ClientID %>").focus();
}
</script>

<body onload="RegisterEvent()">
0
scm0smlAuthor Commented:
wont that mean everytime the page loads the one specific textbox will be given focus?
0
Akin DeluI’m a software engineer, tech enthusiast and UI/UX lover. Commented:
yeah thats true, then set the RegisterEvent() function in the onchange event of the textbox that will trigger the database call

sample
==========

<asp:TextBox ID="TextBox3" onchange="RegisterEvent()" runat="server" AutoPostBack="True" OnTextChanged="TextBox3_TextChanged"></asp:TextBox>
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

scm0smlAuthor Commented:
seems as if the whole page is losing focus?

Your solution didn't work until I randomly put an alert('test'); before it, then once I have clicked the ok....the next textbox has focus...

Whatever this problem is is probably the reason it wasn't doing it initially does that sound right?

Any ideas?
0
scm0smlAuthor Commented:
Sorry when I say before it I mean:
 function endRequestHandler(sender)
        {
        alert('HEY1');
            document.getElementById('ctl00_maincontent_ucInvoice_ucInvoiceQuery_txtInvCP').focus();
           
        }
0
scm0smlAuthor Commented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scm0smlAuthor Commented:
Had no answers to fix this but found a solution myself.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.