Server Side FindControl Based on ClientID

I'm trying to find a control based on the ClientID of an object. When I find the control with the last focus, I'd like the focus to return to the returned to this control.

For example, I have a texbox and a dropdown on the screen in that order. The textbox has a textchanged command. When i tab to the dropdown, I want the focus to be retained in the dropdown without any "screen flashing".

My best option was to create a hidden field and setup an onfocus event for every control on the page that updates this hidden field.  

On a postback, I am retrieving this hidden text field value that contains the ClientID of the last focused control on the page. When I use the FindControl command,  the Control is null.

The problem is that I am using MasterPages and User Web Controls that add the prefix of the naming container to the ClientID.

Is this the best option to keep the focus on postback or is there a way to map the ClientID to the serverID without looping through all the controls on the page one by one?

Who is Participating?
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.

From serverside call the javascript function. In javascript get the hidden control value and set the focus to control.

Javascript function:
function ctrlFocus()
    var ctrlID = document.getElementById('<%=hiddencontrolID.ClientID%>').value;

Server side code to call javascript:
Page.ClientScript.RegisterStartupScript(this.GetType(), "mail", "<script language=JavaScript>ctrlFocus();</script>");

Open in new window


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
klm555Author Commented:
Quick and simple integration. Top Effort!!!
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
.NET Programming

From novice to tech pro — start learning today.