Вопрос

In a project we are using teleriks RadAjaxManagerProxy to send AJAX requests and I was delegated the easy task to implement a scroll-to-top-of-the-screen behaviour through javascript after an AJAX call. This was not at all as easy as expected.

Among other things, I have tried placing my javascript function directly on the page, I have worked with RadAjaxManager.ResponseScript and I have tested with jquery AJAX functions but still no progress. Does anybody have a good clue how to solve it?

This is my latest attempt and I did actually make it work if putting an alert into the code, like this:

ScriptManager.RegisterStartupScript(Page, typeof(Page), "ScrollToTop", "alert('hello');", true);

But whenever I try to insert javascript code like window.location = '#'; or window.scrollTo(0,0); it nevertheless doesn't scroll to top. What am I missing?

Это было полезно?

Решение

ScriptManager.RegisterStartupScript is used only together with UpdatePanels, which I didn't use on my page. Instead I found a solution based on getting the actual RadAjaxManagerProxy for the page. This was done by using the function GetCurrent() on the MasterPage's RadAjaxManager. Hopefully this will save some hours for anyone else with the same problem! My solution:

RadAjaxManager.GetCurrent(Page).ResponseScripts.Add("window.scrollTo(0, 0);");
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top