ASP.NET UpdatePanels and Lost Focus on new Controls

Posted on 2012-09-14
Medium Priority
Last Modified: 2013-04-01

I have a Web USER Control that has 50 textbox’s on them I don’t want to have the user to ever be forced to hit a “Save” or  “Submit” button.   I want to have each edit change instantly recorded and stored in a database in my codebehind.  (I can not use a webservice or database code in my client side scripts).

I tried wrapping each control in it’s own asp:UpdatePanel – the page doesn't flash anymore but there is a  problem.  When the user edits one textbox (say “TextBox1”) and then clicks on another textbox (say “TextBox2”), TextBox 2 does at first shows the edit cursor but after texbox1's autopostback / callback is called, TextBox2 loses focus and then the user must click  on TextBox2 again to go back to editing.  

I’ve read why this happens but I am trying to find a SIMPLEST way to solve this without having to rewrite the whole interface.   I am assuming this can't be done with codebehind and I must use script.    Does anyone know of an asp.net example using ajax codebehind and some easy script so that after the codebehind is called - the NEWLY focused textbox will be rendered with the focus which triggered the whole ajaxupdate to begin with?

Thanks in advance.
Question by:vamail2

Expert Comment

ID: 38401073
This might work ScriptManager.GetCurrent(this.Page).SetFocus(this.FirstNameTextBox)


Author Comment

ID: 38401118
Thank you for your help.   I realize it's a little tricky and I may not have explained it well.    

Your suggestion solution doesn't apply because it assumes I know the textbox that should get focus.  My issues is that I need to know which textbox got the focus and then reset it.

Expert Comment

ID: 38401157
Ah ok well in that case you can save the textbox I'd in a hidden field with a runatserver property on click JavaScript.  Then you can find the textbox based on the hidden value textbox I'd in the code behind

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 38401579
Ok.  Do you have a working example of a usercontrol  that does that?    I am assuming ally controls still have autopostback=true correct and this hidden button is just a method to store info who was focused.   Still not sure of what code I need where.  Would be grateful for real example.
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38403372
I realize it's a little tricky and I may not have explained it well.
You have explained well but without code its always difficult for us to understand completely.
Can u paste a sample code which can reproduce the issue for us .


Accepted Solution

vamail2 earned 0 total points
ID: 38416372
After researching forever on the web, I ended up just using JQuery and calls to code behind.

Author Comment

ID: 38755013
Hi.  How do I close this thread?
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 39036756
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question