Still Cannot Get Focus() Working When FormDecorator on Form

13 posts, 0 answers
  1. Kevin
    Kevin avatar
    61 posts
    Member since:
    Oct 2008

    Posted 13 Jan 2009 Link to this post

    I've read multiple posts on this and tried them all to no avail.  I have a simple login page with asp:textbox controls, a checkbox, and a submit button (default).  When I have a formdecorator on the form I cannot set initial focus to the first entry field no matter what I try.  But when taking off the formdecorator things work fine.

    I've tried (per other posts):
    1. a kludgy delay in js before setting focus
    2. setting via page_load
    3. setting via page_prerender
    4. setting via form defaultfocus attribute
    5. adding style to force certain tags to visible

    I use formdecorator on MANY other pages and only now find that I can't set initial focus.

    Has anyone found a fix for this?

    I'm using version 2008.3.1105.35.

    Testing with IE7 and Chrome and Firefox 3.0.5

    Help!  Thanks,
    Kevin
  2. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 16 Jan 2009 Link to this post

    Hello Kevin,

    I believe that the following forum thread will be of help:
    http://www.telerik.com/community/forums/aspnet-ajax/form-decorator/2008-q3-doesn-t-work-with-focus.aspx

    In general, the workaround for the moment is to use the client-side API and set the focus there:

    protected void Page_Load(object sender, EventArgs e) 
        if (!IsPostBack) 
        { 
    //                txtUsername.Focus(); 
            ScriptManager.RegisterStartupScript(thisthis.GetType(),  
                "setfocus",  
                "Sys.Application.add_load(function f(){$get('" + txtUsername.ClientID + "_text').focus(); Sys.Application.remove_load(f);});",  
                true); 
        } 
     

    We are working on improving the behavior of the RadFormDecorator control in such scenario, but at this point I cannot give an exact timeframe. If you experience problems with the suggested solution, please open a support ticket and send us a small sample project where they can be reproduced.


    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy
    Andy avatar
    9 posts
    Member since:
    Mar 2006

    Posted 19 Jan 2009 Link to this post

    I'm also having this problem.  The fix suggested seems to work but is a little cumbersome.

    I really want to use the form decorator but if this doesn't get fixed soon I may have to drop it as my appication is due to be rolled out in March.

    Regards

    Andy
  5. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 20 Jan 2009 Link to this post

    Hi Andy,

    We are currently working on a permanent solution. If everything goes well and the solution produce consistent results in all major browsers, we will implement it in RadFormDecorator for the Q1 2009 release.
    In general, the approach that we are working on is based on the logic below - you can try it by putting the JavaScript code in your page:

    //Solving the autofocus problem when RadFormDecorator is on the page 
    if (typeof(WebForm_AutoFocus) != "undefined"
        var old_WebForm_AutoFocus = WebForm_AutoFocus;     
         
        WebForm_AutoFocus = function (arg) 
        {         
            pageLoad = function() 
            {      
                old_WebForm_AutoFocus(arg); 
            }; 
        }             


    Greetings,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Moon
    Moon avatar
    249 posts
    Member since:
    Oct 2012

    Posted 22 Jan 2009 Link to this post

    I reported this on dec. 8th as a support ticket and found this today.

    I put the code you suggested in a separate .js file and included this in my Page_Load on my master page:

    Page.Header.Controls.Add(

    New LiteralControl("<style type=""text/javascript"">@import """ & ResolveClientUrl("~/Site/Scripts/Styles/Scripts/TelerikJavascript.js") & """;</style>"))

    It doesn't work that way. It only works when added manually at the top of the code-in-front of the page that has the radformdecorator.

    Can it not work as an include? Did I do something wrong?

    thanks.

    Moon.

     

  7. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 23 Jan 2009 Link to this post

    Hello Moon,

    With the code that you want to use, you can import styles but not JavaScript files - if you put a simple alert in your JS, you will notice that it is not called when the page is loaded.

    In addition, for this code to work, it must be executed after the ASP.NET AJAX ScriptManager has been loaded. That is why I would suggest to insert the JS after the Scriptmanager's declaration:

    <form id="form1" runat="server"
        WebForm_AutoFocus 
        <asp:ScriptManager ID="ScriptManager1" runat="server"
        </asp:ScriptManager> 
     
        <script type="text/javascript" src="jscript.js"></script> 
     
        <telerik:RadFormDecorator ID="RadFormDecorator1" Visible="true" DecoratedControls="all" 
            runat="server" /> 
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
        <asp:Button ID="Button1" Text="Text" runat="server" /> 
    </form> 


    Kind regards,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Moon
    Moon avatar
    249 posts
    Member since:
    Oct 2012

    Posted 23 Jan 2009 Link to this post

    Should we be using the scriptManager instead of the RadScriptManager?

    I tried that and it didn't work. I had to put the script actually in the file for it to work....

        <telerik:RadScriptManager ID="_sm" runat="server">
            <Scripts>
                <asp:ScriptReference Path="~/Site/Scripts/Star/Common/csshelper.js" />
                <asp:ScriptReference Path="~/Site/Scripts/Star/Common/iepngfix.js" />
            </Scripts>   
        </telerik:RadScriptManager>
       
       <script type="text/javascript" src="~/Site/Scripts/Scripts/TelerikJavascript.js"></script>

  9. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 26 Jan 2009 Link to this post

    Hi Moon,

    It doesn't matter if you are using asp:scriptmanager control or RadScriptManager - the logic stays the same. Since I don't know what you exact setup is, I cannot tell what is going wrong on your side as the code is working fine regardles of the script manager used.
    For convenience I attached a small sample that used RadScriptManager and is working as expected. Please check it and if you still experience problems - open a support ticket and send us your application or a small sample one where the problem can be reproduced.


    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Andy
    Andy avatar
    9 posts
    Member since:
    Mar 2006

    Posted 05 Mar 2009 Link to this post

    Has this been implemented in the Q1 2009 Beta? 

     
    I've just found a bug with the suggested fix where I have MaintainScrollPositionOnPostback="true" on my page. 

    Maybe I'm doing something wrong, but I just want the focus to be set on initial page load, not on subsequent post backs, however it's setting it on every page load.

    My Page_Load looks like:

    If Not IsPostBack Then 
     
       RadScriptManager.RegisterStartupScript(MeMe.GetType(), "setfocus", _  
       "Sys.Application.add_load(function f(){$get('" & CourseIdRadTextBox.ClientID & "_text').focus(); Sys.Application.remove_load(f);});"True)  
     
       Page.Form.DefaultButton = FindButton.UniqueID  
     
    End If 

    Thanks

    Andy

  11. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 06 Mar 2009 Link to this post

    Hello Andy,

    Yes, the focus issue is fixed in Q1 2009 Beta. I invite you to download and try it - the official release will appear next week.

    If you still experience problems, please open a support ticket and send us a small sample project where they could be reproduced.


    Regards,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  12. Priya
    Priya avatar
    144 posts
    Member since:
    Jul 2008

    Posted 16 Apr 2009 Link to this post

    hi
    i too have the same prbm
    tooltipAdd_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles tooltipAdd.Load  
            ' txtTitle.Focus()  
            Dim s As RadScriptManager  
             
            s = DirectCast(Me.Master.FindControl("RadAjaxManager1"), RadScriptManager)  
            s.SetFocus(txtTitle)  
    end sub 
    i used the above code.but not working..hw its possible
    Thanks
  13. Jose
    Jose avatar
    49 posts
    Member since:
    Aug 2008

    Posted 16 Apr 2009 Link to this post

    Hi Kevin.

    I'm not sure if this will work on your scenario as I'm using Q1 2009 controls, but my solution would be: Add a RadCodeBlock with the following script:

    If your textboxes are ASP.NET Textboxes:

        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
        <script type="text/javascript">  
            function pageLoad() {  
                $get("txtUserName").focus();  
            }  
        </script> 
        </telerik:RadCodeBlock> 

    If your textboxes are RadTextBox texboxes then:

        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
        <script type="text/javascript">  
            function pageLoad() {  
                $find("txtUserName").focus();  
            }  
        </script> 
        </telerik:RadCodeBlock> 

    If it works, please mark it as answer.

    Thanks.
    Jose Guay
  14. Faisal saleem
    Faisal  saleem avatar
    1 posts
    Member since:
    Jan 2009

    Posted 03 Jun 2009 Link to this post

    Thanks alot JOSE, it works fine in my case

    Regards,

    Faisal
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017