Set focus to RadInput within RadWindow ContentTamplate on load

5 posts, 1 answers
  1. Bernhard Rosenfelder
    Bernhard Rosenfelder avatar
    24 posts
    Member since:
    Mar 2010

    Posted 04 Apr 2011 Link to this post

    hi community,

    does anyone know how to set the focus on a radinput within radwindow contenttemplate onload. i set VisibleOnPageLoad="true" at the radwindow. i have tried all the described methods on (http://demos.telerik.com/aspnet-ajax/input/examples/common/focus/defaultcs.aspx).

    thanks
    Bernhard
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Apr 2011 Link to this post

    Hello Bernhard,


    Try setting focus to TextBox in OnclientShow event of RadWindow and see whether it helps.

    Sample code:
    var obj;
    function pageLoad() {
        obj = $find('<%= RadTextBox22.ClientID %>');
    }
    function OnWindowShow(sender, args) {
        setTimeout(" obj.focus();", 200);
    }


    And the mark-up is shown below:
    <telerik:RadWindow VisibleOnPageLoad="true" OnClientShow="OnWindowShow" ID="RadWindow1"
        runat="server" Height="300px" Width="450px" Modal="true">
        <ContentTemplate>
            <div id="div1">
                <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
                <telerik:RadTextBox ID="RadTextBox22" runat="server" Skin="Black">
                </telerik:RadTextBox>
            </div>
        </ContentTemplate>
    </telerik:RadWindow>


    Have a nice day.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bernhard Rosenfelder
    Bernhard Rosenfelder avatar
    24 posts
    Member since:
    Mar 2010

    Posted 05 Apr 2011 Link to this post

    hi princy,

    with the code in your sample it is working well.

    thank you!!

    regards,
    bernhard
  5. mark baer
    mark baer avatar
    142 posts
    Member since:
    Sep 2009

    Posted 20 Apr 2011 Link to this post

    I had this same problem.  I tried the code above but it did not work.  I changed it to the code below and was able to get it to work(for anyone else having this problem).

     

    <P><body class="form" onload="pageLoad" ></P>
    <P>    <form id="form1" runat="server" 
    defaultfocus="txtUserName"><BR><telerik:RadScriptManager 
    ID="RadScriptManager1" runat="server"><BR>    
    </telerik:RadScriptManager><BR>    <telerik:RadWindow 
    ID="RadWindow1" runat="server" VisibleOnPageLoad="true" Behaviors="None" 
    Skin="WebBlue" Title="Login to Creative Affairs!" <BR>    
    VisibleStatusbar="False" OnClientShow="OnWindowShow" Modal="true" Height="155px" 
    Width="300px"     
    ><BR>        
    <ContentTemplate><BR>            
    <telerik:RadScriptBlock ID="RadScriptBlock1" 
    runat="server"><BR>                
    <script 
    type="text/javascript"><BR>                    
    var 
    obj;<BR>                    
    function pageLoad() 
    {<BR>                        
    obj = document.getElementById('<%= txtUserName.ClientID 
    %>');<BR>                        
    //alert(obj);<BR>                    
    }<BR>                    
    function OnWindowShow(sender, args) 
    {<BR>                        
    //obj = $find('<%= txtUserName.ClientID 
    %>');<BR>                        
    //alert(obj);<BR>                        
    if (obj != null) 
    {<BR>                            
    setTimeout(" obj.focus();", 
    300);<BR>                        
    }<BR>                    
    } </P>
    <P>                
    </script><BR>            
    </telerik:RadScriptBlock></P>
  6. Gowtham
    Gowtham avatar
    7 posts
    Member since:
    Jun 2013

    Posted 07 May 2014 in reply to Princy Link to this post

    Hi,
          Princy thanks...working fine..
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017