?
Solved

ASP.NET UpdatePanels and Lost Focus on new Controls

Posted on 2012-09-14
10
Medium Priority
?
804 Views
Last Modified: 2013-04-01
Hi

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.
0
Comment
Question by:vamail2
8 Comments
 
LVL 7

Expert Comment

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

stackoverflow.com/questions/1307224/setfocus-to-asptextbox-within-asppanel-within-aspcontent-from-content-page-lo
0
 

Author Comment

by:vamail2
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.
0
 
LVL 7

Expert Comment

by:Padre_Corleone
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

 

Author Comment

by:vamail2
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.
0
 
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 .

Meeran03
0
 

Accepted Solution

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

Author Comment

by:vamail2
ID: 38755013
Hi.  How do I close this thread?
0
 
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.
0

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