This is a migrated thread and some comments may be shown as answers.

Set focus on page load

4 Answers 156 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Steve LaForge
Top achievements
Rank 1
Steve LaForge asked on 21 Mar 2008, 06:31 PM
I have an app that uses a combobox on a page where I want to set the focus to the combobox on the page load.  I have used this technique with previous versions of the radCombobox.

I am using the ChangeInputColor() function documented in ms-help://telerik.radcontrols.prometheus.2007.Q3/telerik.radcontrols.prometheus.2007.Q3/combo_ClientSideRadComboBox.html as my prototype for trying this with the Prometheus controls.

My radCombobox definition looks like:

<

telerik:radcombobox id="cmboUsers" runat="server" radcomboboximageposition="Right">
  <Items>
    <telerik:RadComboBoxItem runat="server" Text="Select a user..."></telerik:RadComboBoxItem>
  </Items>
  <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
  <ExpandAnimation Type="OutQuart"></ExpandAnimation>
</telerik:radcombobox>

My body tag looks like:

<

body onload="fnMaxWindow();fnSetFocus();">

My JavaScript code looks like:

<
script language="javascript" type="text/javascript">
function fnSetFocus()
{
  var combo = $find("<%= cmboUsers.ClientID %>");
  alert(
"combo = " + combo);
  var inputArea = combo.get_inputDomElement();
  alert(
"inputArea = " + inputArea);
  inputArea.focus();
}

function
fnMaxWindow() {
  window.moveTo(0,0);
  window.resizeTo(screen.width, screen.height);
}
</script>

When this runs, I get "combo = null" on the first alert, indicating that the $find code doesn't work.

Thanks in advance for the help.

4 Answers, 1 is accepted

Sort by
0
Steve LaForge
Top achievements
Rank 1
answered on 21 Mar 2008, 09:39 PM
I found the answer...as soon as I set "MarkFirstMatch" to true, this code started working.  This isn't an issue with the old style in previous versions, but causes the JS error in Prometheus.  I guess it needs some code added to check to verify that the combobox could be found.
0
Rosi
Telerik team
answered on 24 Mar 2008, 12:02 PM
Hello Steve,

"Prometheus" controls are not completely ready for use on load event of the page. I suggest you use Sys.application.load instead.

All you have to do is that edit your javascript as follows:
<script language="javascript" type="text/javascript">  
 
function pageLoad()  
 
{  
    fnMaxWindow();  
    fnSetFocus();  
 
}  
function fnSetFocus()  
{  
  var combo = $find("<%= cmboUsers.ClientID %>");  
  alert("combo = " + combo);  
  var inputArea = combo.get_inputDomElement();  
  alert("inputArea = " + inputArea);  
  inputArea.focus();  
}  
 
function fnMaxWindow() {  
  window.moveTo(0,0);  
  window.resizeTo(screen.width, screen.height);  
}  
 
 
</script> 

Hope this helps.

Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 10 Jan 2009, 07:57 PM

I'm having some trouble with this.  Seems a simple thing to set focus on page load but I'm not quite getting it.  Here's what I'm attempting with the Q3 combobox.

if (!Page.IsPostback)

{

  radcombobox.focus();

}

 

Should that work or do I need to use the client script suggestion above?

 

Thanks

Mark

0
Yana
Telerik team
answered on 12 Jan 2009, 08:16 AM
Hi Mark,

Please check this help article which shows how  to focus RadComboBox on the server.

Greetings,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Steve LaForge
Top achievements
Rank 1
Answers by
Steve LaForge
Top achievements
Rank 1
Rosi
Telerik team
Mark
Top achievements
Rank 1
Yana
Telerik team
Share this question
or