[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Server Side FindControl Based on ClientID

Posted on 2010-03-26
2
Medium Priority
?
1,447 Views
Last Modified: 2013-11-26
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?

0
Comment
Question by:klm555
2 Comments
 
LVL 12

Accepted Solution

by:
rajapandian_81 earned 1000 total points
ID: 28673467
Hi,
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;
    document.getElementById(ctrlID).focus();
}

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

Open in new window

0
 
LVL 1

Author Closing Comment

by:klm555
ID: 31707447
Quick and simple integration. Top Effort!!!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

590 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