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

Still Cannot Get Focus() Working When FormDecorator on Form

12 Answers 244 Views
FormDecorator
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 2
Kevin asked on 13 Jan 2009, 11:00 PM
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

12 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 16 Jan 2009, 02:32 PM
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.
0
Andy
Top achievements
Rank 2
answered on 19 Jan 2009, 03:45 PM
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
0
Georgi Tunev
Telerik team
answered on 20 Jan 2009, 09:23 AM
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.
0
Moon
Top achievements
Rank 2
answered on 22 Jan 2009, 04:06 PM
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.

 

0
Georgi Tunev
Telerik team
answered on 23 Jan 2009, 10:20 AM
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.
0
Moon
Top achievements
Rank 2
answered on 23 Jan 2009, 08:55 PM
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>

0
Georgi Tunev
Telerik team
answered on 26 Jan 2009, 01:12 PM
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.
0
Andy
Top achievements
Rank 2
answered on 05 Mar 2009, 06:09 PM
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

0
Georgi Tunev
Telerik team
answered on 06 Mar 2009, 03:33 PM
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.
0
Priya
Top achievements
Rank 1
answered on 16 Apr 2009, 06:53 AM
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
0
Jose
Top achievements
Rank 2
answered on 16 Apr 2009, 03:06 PM
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
0
Faisal saleem
Top achievements
Rank 1
answered on 03 Jun 2009, 10:08 AM
Thanks alot JOSE, it works fine in my case

Regards,

Faisal
Tags
FormDecorator
Asked by
Kevin
Top achievements
Rank 2
Answers by
Georgi Tunev
Telerik team
Andy
Top achievements
Rank 2
Moon
Top achievements
Rank 2
Priya
Top achievements
Rank 1
Jose
Top achievements
Rank 2
Faisal saleem
Top achievements
Rank 1
Share this question
or