Using RadScriptManager for RegisterStartupScript

7 posts, 0 answers
  1. Matt
    Matt avatar
    24 posts
    Member since:
    Dec 2012

    Posted 05 Jun 2013 Link to this post

    Hello,

    I have a RadTreeView that has nodes that use NodeExpandMode.ServerSide and I need to have the web page focus on the selected node after post back. I found the following code from these forums to do that:

    ScriptManager.RegisterStartupScript(
    this, GetType(), ClientID,
    string.Format("Sys.Application.add_load(function(){{$find('{0}').get_element().focus();}}, 0);", AppTreeView.ClientID), 
    true);

    Unfortunately, this project was made in Visual Studio 2005 which only has the .NET version of 2.0 which doesn't have the ScriptManager class.

    I was wondering if RadScriptManager would be able to provide this functionality, and if so, could I be provided with an example on how to do this?

    Thanks,
    Matt
  2. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 06 Jun 2013 Link to this post

    Hi Matt,

    Here is an example how you could achieve it with the RadScriptManager.
    protected void Page_Load(object sender, EventArgs e)
    {
        RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "1", "Sys.Application.add_load(function(){{alert('success');}}, 0);", true);
    }

    Regards,
    Peter Filipov
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Matt
    Matt avatar
    24 posts
    Member since:
    Dec 2012

    Posted 10 Jun 2013 Link to this post

    I've tried your solution however it doesn't work and I get these errors in the browser:

    1. ASP.NET Ajax client-side framework failed to load.

    2. 'Sys' is undefined.

    I read that "'Sys' is undefined" could be due to the script manager not being declared in the .aspx file, but it is:

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="tWebUI" %>
      
    <tWebUI:RadScriptManager ID="RadScriptManager1" runat="server">
            </tWebUI:RadScriptManager>

    Thanks,
    Matt
  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 12 Jun 2013 Link to this post

    Hi Matt,

    It is really strange that the ajax framework is not loaded. Could you please test the attached page at you side. Which version of our controls are you using?

    Regards,
    Peter Filipov
    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.
  6. Matt
    Matt avatar
    24 posts
    Member since:
    Dec 2012

    Posted 12 Jun 2013 Link to this post

    I'm using version 2013.1.403.35 of Telerik.Web.UI. I moved some things around and now I'm getting the following:

    Unable to cast object of type 'System.Web.Configuration.ScriptingProfileServiceSection' to type 'System.Web.Configuration.ScriptingProfileServiceSection'. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
      
    Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.Configuration.ScriptingProfileServiceSection' to type 'System.Web.Configuration.ScriptingProfileServiceSection'.
      
    Source Error: 
      
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
      
    Stack Trace: 
      
      
    [InvalidCastException: Unable to cast object of type 'System.Web.Configuration.ScriptingProfileServiceSection' to type 'System.Web.Configuration.ScriptingProfileServiceSection'.]
       System.Web.Configuration.ScriptingProfileServiceSection.GetConfigurationSection() +41
       System.Web.ApplicationServices.ApplicationServiceHelper.EnsureProfileConfigLoaded() +47
       System.Web.UI.ProfileServiceManager.GenerateInitializationScript(StringBuilder& sb, HttpContext context, ScriptManager scriptManager, String serviceUrl, ArrayList loadedProperties) +79
       System.Web.UI.ProfileServiceManager.ConfigureProfileService(StringBuilder& sb, HttpContext context, ScriptManager scriptManager, List`1 proxies) +530
       System.Web.UI.ScriptManager.ConfigureApplicationServices() +38
       System.Web.UI.ScriptManager.RegisterUniqueScripts(List`1 uniqueScripts) +290
       System.Web.UI.ScriptManager.RegisterScripts() +386
       System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e) +113
       System.EventHandler.Invoke(Object sender, EventArgs e) +0
       System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +8722194
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1029
  7. Matt
    Matt avatar
    24 posts
    Member since:
    Dec 2012

    Posted 12 Jun 2013 Link to this post

    Well I fixed the above but I'm back to my original errors...
  8. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 13 Jun 2013 Link to this post

    Hello Matt,

    Could you clarify that you tested the sample page from my previous post and it is not working properly at you side. In case that everything is working properly could you please send me a live URL or setup a runnable sample based on the provided page that reproduces the problem and send it back for a local test.

    Regards,
    Peter Filipov
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017