Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Input / Server/Client Focus



RadTextBox:


RadMaskedTextBox:


RadNumericTextBox:


RadDateInput:
Example Configuration
Disable/Enable Ajax
Change selection on focus options:
select

  • RadInput's server and client-side API allows the control to be focused both on the server and on the client using the respective method. You can put the focus on a specific RadInput control dynamically, or you can specify a RadInput control that should get the focus by default. You can set the default focus for the form as a whole, or you can set the default focus on a control that is a child of a Panel control.

    ASP.NET provides two different solutions if you need to set focus dynamically:

    • You can call a control's Focus method
    • You can use the Page.SetFocus method with control's ID as a parameter

    Furthermore RadAjaxPanel/RadAjaxManager has a FocusControl method that lets you set focus to desired controls. You can use the RadAjaxPanel.FocusControl/RadAjaxManager.FocusControl methods to set focus to a control after the Ajax request is complete: RadAjaxPanel1.FocusControl(RadInput1.ClientID + "_text")
    RadAjaxManager1.FocusControl(RadInput1.ClientID + "_text")

    Finally you can set the focus via the client-side focus() method.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="VB" AutoEventWireup="false" CodeFile="DefaultVB.aspx.vb" Inherits="Telerik.InputExamplesVB.Common.Focus.DefaultVB" %>

    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server"></qsf:HeadTag>
        
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            <!--
                function Focus(id)
                {
                    var radInput = $find(id);
                    radInput.focus();
                }
                function Start(sender, args)
                {
                    if ((args.get_eventTarget().match("^" + "Button") == "Button") && !($get("CheckBox1").checked)) // disable Ajax
                    {
                        args.set_enableAjax(false);
                    }
                }
                -->
                
        </script>
        </telerik:RadCodeBlock>
    </head>
    <body class="BODY">
        <form id="mainForm" method="post" runat="server">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="VB" ShowSkinChooser="true">
        </qsf:Header>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <br />
        <br />
        <asp:Panel ID="Panel1" runat="server">
        RadTextBox:
        <br />
        <telerik:RadTextBox ID="RadTextBox1" runat="server" SelectionOnFocus="CaretToBeginning" ></telerik:RadTextBox>
    <asp:Button ID="Button1" runat="server" CssClass="qsfButton" Text="Client-side focus"
    OnClientClick="Focus('RadTextBox1'); return false" />

        <asp:Button ID="Button5" runat="server" CssClass="qsfButton" Text="Server-side focus" OnClick="Button5_Click" />
        <br /><br />
        
        RadMaskedTextBox:
        <br />
        <telerik:RadMaskedTextBox ID="RadMaskedTextBox1" runat="server" Mask="###-#####" SelectionOnFocus="CaretToBeginning"
            ></telerik:RadMaskedTextBox>
    <asp:Button ID="Button2" runat="server" CssClass="qsfButton" Text="Client-side focus"
    OnClientClick="Focus('RadMaskedTextBox1'); return false" />

        <asp:Button ID="Button6" runat="server" CssClass="qsfButton" Text="Server-side focus" OnClick="Button6_Click" />
        <br /><br />
        
        RadNumericTextBox:
        <br />
        <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" SelectionOnFocus="CaretToBeginning" ></telerik:RadNumericTextBox>
    <asp:Button ID="Button3" runat="server" CssClass="qsfButton" Text="Client-side focus"
    OnClientClick="Focus('RadNumericTextBox1'); return false" />

        <asp:Button ID="Button7" runat="server" CssClass="qsfButton" Text="Server-side focus" OnClick="Button7_Click" />
        <br /><br />
        
        RadDateInput:
        <br />
        <telerik:RadDateInput ID="RadDateInput1" runat="server" SelectionOnFocus="CaretToBeginning" ></telerik:RadDateInput>
    <asp:Button ID="Button4" runat="server" CssClass="qsfButton" Text="Client-side focus"
    OnClientClick="Focus('RadDateInput1'); return false" />

        <asp:Button ID="Button8" runat="server" CssClass="qsfButton" Text="Server-side focus" OnClick="Button8_Click" />
        
        </asp:Panel>
        
        <qsf:ConfiguratorPanel ID="ConfiguratorPanel1" runat="server" Expanded="true">
            Disable/Enable Ajax
            <asp:CheckBox ID="CheckBox1" runat="server" Checked="true" />
            <div style="display:inline; padding-left:50px">
                Change selection on focus options:
                <telerik:RadComboBox ID="SelectionOnFocusOptions" runat="server" AutoPostBack="true"
                    OnSelectedIndexChanged="SelectionOnFocusOptions_SelectedIndexChanged">
                    <Items>
                        <telerik:RadComboBoxItem Text="CaretToBeginning" Value="CaretToBeginning" Selected="false" />
                        <telerik:RadComboBoxItem Text="CaretToEnd" Value="CaretToEnd" Selected="false" />
                        <telerik:RadComboBoxItem Text="SelectAll" Value="SelectAll" Selected="false" />
                    </Items>
                </telerik:RadComboBox>
            </div>
        </qsf:ConfiguratorPanel>
        
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1" UpdatePanelsRenderMode="Inline">
            <AjaxSettings>
               <telerik:AjaxSetting AjaxControlID="Panel1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Panel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="ConfiguratorPanel1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="ConfiguratorPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="Panel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
            <ClientEvents OnRequestStart="Start" />
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Vista" MinDisplayTime="400" >
        </telerik:RadAjaxLoadingPanel>
        <qsf:Footer ID="Footer1" runat="server"></qsf:Footer>
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451