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?
 
scm0smlAuthor Commented:
0
 
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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
 
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:
Had no answers to fix this but found a solution myself.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.