7 Answers, 1 is accepted
0
Hi Nick,
There are two cases when I have seen such behavior and they are both related to the way the browser works:
1) if you are opening the RadWindow onclick of an anchor and the anchor's href attribute is set to a sharp sign (#) the browser will scroll the target into view, which can cause this behavior. You need to change the href to javascript:void(0); This will also apply to ASP LinkButtons - OnClientClick and NavigateUrl are the properties that render as the onclick and href attributes
2) The page/content you have inside the RadWindow has default focus, especially set on the server (e.g. TextBox1.Focus() in the Page_Load handler). This also causes the browser to scroll to the focused element. The way to avoid it is to either remove the default focus, or to use JavaScript and a small timetout in the Sys.Application.Load event.
Regards,
Marin Bratanov
the Telerik team
There are two cases when I have seen such behavior and they are both related to the way the browser works:
1) if you are opening the RadWindow onclick of an anchor and the anchor's href attribute is set to a sharp sign (#) the browser will scroll the target into view, which can cause this behavior. You need to change the href to javascript:void(0); This will also apply to ASP LinkButtons - OnClientClick and NavigateUrl are the properties that render as the onclick and href attributes
2) The page/content you have inside the RadWindow has default focus, especially set on the server (e.g. TextBox1.Focus() in the Page_Load handler). This also causes the browser to scroll to the focused element. The way to avoid it is to either remove the default focus, or to use JavaScript and a small timetout in the Sys.Application.Load event.
Regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Nick
Top achievements
Rank 1
answered on 28 Sep 2012, 05:14 AM
Hi Marin!
The information provided by you is helpful..
Appreciate your response.
Thanks a lot..
The information provided by you is helpful..
Appreciate your response.
Thanks a lot..
0

Bob Areddy
Top achievements
Rank 1
answered on 18 Jan 2013, 04:38 PM
Marin,
Can you give a sample of the code that would fix the 2nd scenario? Thanks.
Can you give a sample of the code that would fix the 2nd scenario? Thanks.
0
Hello Bob,
Here is a simple example:
You can, of course, declare the function in the page's markup, call it from the code behind and only pass the ClientID of the desired control as a parameter. This depends on your preferences.
Greetings,
Marin Bratanov
the Telerik team
Here is a simple example:
//instead of
//TextBox1.Focus();
string
script =
"function f(){setTimeout(function(){$get('"
+ TextBox1.ClientID +
"').focus();},0);Sys.Application.remove_load(f);}Sys.Application.add_load(f);"
;
ScriptManager.RegisterStartupScript(
this
.Page,
typeof
(Page),
"focusingKey"
, script,
true
);
You can, of course, declare the function in the page's markup, call it from the code behind and only pass the ClientID of the desired control as a parameter. This depends on your preferences.
Greetings,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Randy
Top achievements
Rank 1
answered on 09 Aug 2013, 06:44 PM
I was sent here from another post but I cannot get the JavaScript to work correctly.
I changed it to call a function defined on the ASPX page with the setTimeout, but no matter what, the parent page scrolls to the top of the screen behind the radwindow. It does return to where it should be when the window closes, but we really don't want the parent screen to scroll in the first place.
Thanks,
Randy
I changed it to call a function defined on the ASPX page with the setTimeout, but no matter what, the parent page scrolls to the top of the screen behind the radwindow. It does return to where it should be when the window closes, but we really don't want the parent screen to scroll in the first place.
function setFocusName()
{
setTimeout($get('tFirstName').focus(), 0);
}
Dim
script
As
New
StringBuilder
script.Append(
"function f()"
)
script.Append(
"{"
)
script.Append(
" setFocusName();"
)
script.Append(
" Sys.Application.remove_load(f);"
)
script.Append(
"}"
)
script.Append(
"Sys.Application.add_load(f);"
)
ScriptManager.RegisterStartupScript(Page, Page.
GetType
,
"focusingKey"
, script.ToString(),
True
)
Thanks,
Randy
0
Hi Randy,
There may be other reasons for this behavior like an anchor with href="#" or a postback.
Solution for the former is using href="javascript:void(0);" and using partial postbacks for the latter, as they do not usually affect the page scrolling.
If neither helps I would suggest that you post here the code that leads to the problem in its minimal version (i.e. the way you open the RadWindow and the simplest content page that shows the problem). Only once we can examine the problem we may be able to help.
Regards,
Marin Bratanov
Telerik
There may be other reasons for this behavior like an anchor with href="#" or a postback.
Solution for the former is using href="javascript:void(0);" and using partial postbacks for the latter, as they do not usually affect the page scrolling.
If neither helps I would suggest that you post here the code that leads to the problem in its minimal version (i.e. the way you open the RadWindow and the simplest content page that shows the problem). Only once we can examine the problem we may be able to help.
Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0

Jonathan
Top achievements
Rank 1
answered on 21 May 2015, 03:34 AM
Using a jquery timeout seems to work after setting the ClientIDMode to static on the control to which you wish to set focus:
$(document).ready(function () {
setTimeout(function () { $('#txtComment').focus(); }, 100);
});