EnableEmbeddedScripts as false giving some problem

2 posts, 0 answers
  1. Asp Net
    Asp Net avatar
    3 posts
    Member since:
    Sep 2011

    Posted 24 Apr 2012 Link to this post

    Hi

    I'm placeing RadMenu in page and add made EnableEmbeddedScripts as false for this control and adding javascript files through code like this

    protected void Page_Load(object sender, EventArgs e)

            {

                 RadMenu1.EnableEmbeddedScripts = false;

                ScriptReference referenceCore = AddJSReference("Telerik.Web.UI.Common.Core.js", false, RadMenu1);

                Page.ClientScript.RegisterClientScriptInclude(referenceCore.Name, referenceCore.Path);

                ScriptReference referenceQuery =AddJSReference("Telerik.Web.UI.Common.jQuery.js", false, RadMenu1);

                Page.ClientScript.RegisterClientScriptInclude(referenceQuery.Name, referenceQuery.Path);

                ScriptReference referenceQueryPlugin = AddJSReference("Telerik.Web.UI.Common.jQueryPlugins.js", false, RadMenu1);

                Page.ClientScript.RegisterClientScriptInclude(referenceQueryPlugin.Name, referenceQueryPlugin.Path);

                ScriptReference referenceNavigationScripts = AddJSReference("Telerik.Web.UI.Common.Navigation.NavigationScripts.js", false, RadMenu1);

                Page.ClientScript.RegisterClientScriptInclude(referenceNavigationScripts.Name, referenceNavigationScripts.Path);

                ScriptReference referenceRadMenuScripts = AddJSReference("Telerik.Web.UI.Menu.RadMenuScripts.js", false, RadMenu1);

                Page.ClientScript.RegisterClientScriptInclude(referenceRadMenuScripts.Name, referenceRadMenuScripts.Path);

     

            }

     

            public ScriptReference AddJSReference(string scriptName, bool IsExecutingAssembly, Control objectControl)

            {

                string[] Names;

                string DLLName;

                string VersionNumber;

                string Culture;

                string PublicKeyToken;

                ScriptReference reference = new ScriptReference();

                reference.Name = scriptName;

                if (IsExecutingAssembly)

                    reference.Assembly = Assembly.GetExecutingAssembly().FullName;

                else

                    reference.Assembly = Assembly.GetAssembly(objectControl.GetType()).FullName;

     

                Names = reference.Assembly.Split(',');

                DLLName = Names[0].Replace("\\", "");

                VersionNumber = Names[1].Split('=')[1].Replace("\\", "");

                Culture = Names[2].Split('=')[1].Replace("\\", "");

                PublicKeyToken = Names[3].Split('=')[1].Replace("\\", "");

                reference.Path = "~/MyScriptHandler.ashx?Assembly=" + DLLName +

                    "&VersionNumber=" + VersionNumber +

                    "&Culture=" + Culture +

                    "&PublicKeyToken=" + PublicKeyToken +

                    "&ResourceName=" + reference.Name;

     

                return reference;

     

            }



    After running this page MenuItems are not appearing on click of main menu. Please suggest some sample code or work around to get rid of this issue.

     

  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 27 Apr 2012 Link to this post

    Hi,

    That's an interesting way to add scripts from an assembly dynamically. I susspect the problem could be related to your ASHX handler.

    Have you tried following a more conventional way such as the one described here -
    Dynamically Assigning Script References? Here is the code I tested which worked fine at my side. Attached is a simple demo for reference.
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
       </telerik:RadScriptManager>
       <telerik:RadMenu ID="RadMenu1" runat="server">
           <Items>
               <telerik:RadMenuItem runat="server" Text="Root RadMenuItem1">
                   <Items>
                       <telerik:RadMenuItem runat="server" Text="Child RadMenuItem 1">
                       </telerik:RadMenuItem>
                       <telerik:RadMenuItem runat="server" Text="Child RadMenuItem 2">
                       </telerik:RadMenuItem>
                   </Items>
               </telerik:RadMenuItem>
               <telerik:RadMenuItem runat="server" Text="Root RadMenuItem2">
                   <Items>
                       <telerik:RadMenuItem runat="server" Text="Child RadMenuItem 1">
                       </telerik:RadMenuItem>
                       <telerik:RadMenuItem runat="server" Text="Child RadMenuItem 2">
                       </telerik:RadMenuItem>
                   </Items>
               </telerik:RadMenuItem>
               <telerik:RadMenuItem runat="server" Text="Root RadMenuItem3">
               </telerik:RadMenuItem>
           </Items>
       </telerik:RadMenu>

    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadMenu1.EnableEmbeddedScripts = false;
     
     
            ScriptReference referenceCore = AddJSReference("Telerik.Web.UI.Common.Core.js", false, RadMenu1);     
     
            //Page.ClientScript.RegisterClientScriptInclude(referenceCore.Name, referenceCore.Path);
            RadScriptManager1.Scripts.Add(referenceCore);
     
            ScriptReference referenceQuery = AddJSReference("Telerik.Web.UI.Common.jQuery.js", false, RadMenu1);
     
            //Page.ClientScript.RegisterClientScriptInclude(referenceQuery.Name, referenceQuery.Path);
            RadScriptManager1.Scripts.Add(referenceQuery);
     
            ScriptReference referenceQueryPlugin = AddJSReference("Telerik.Web.UI.Common.jQueryPlugins.js", false, RadMenu1);
     
            //Page.ClientScript.RegisterClientScriptInclude(referenceQueryPlugin.Name, referenceQueryPlugin.Path);
            RadScriptManager1.Scripts.Add(referenceQueryPlugin);
            
            ScriptReference referenceNavigationScripts = AddJSReference("Telerik.Web.UI.Common.Navigation.NavigationScripts.js", false, RadMenu1);
             
            //Page.ClientScript.RegisterClientScriptInclude(referenceNavigationScripts.Name, referenceNavigationScripts.Path);
            RadScriptManager1.Scripts.Add(referenceNavigationScripts);
             
            ScriptReference referenceRadMenuScripts = AddJSReference("Telerik.Web.UI.Menu.RadMenuScripts.js", false, RadMenu1);
     
            //Page.ClientScript.RegisterClientScriptInclude(referenceRadMenuScripts.Name, referenceRadMenuScripts.Path);
            RadScriptManager1.Scripts.Add(referenceRadMenuScripts);
        }
        public ScriptReference AddJSReference(string scriptName, bool IsExecutingAssembly, System.Web.UI.Control objectControl)
        {
                 
            string[] Names;
     
            string DLLName;
     
            string VersionNumber;
     
            string Culture;
     
            string PublicKeyToken;
     
            ScriptReference reference = new ScriptReference();
     
            reference.Name = scriptName;
     
            if (IsExecutingAssembly)
     
                reference.Assembly = Assembly.GetExecutingAssembly().FullName;
     
            else
     
                reference.Assembly = Assembly.GetAssembly(objectControl.GetType()).FullName;
     
     
     
            //Names = reference.Assembly.Split(',');
     
            //DLLName = Names[0].Replace("\\", "");
     
            //VersionNumber = Names[1].Split('=')[1].Replace("\\", "");
     
            //Culture = Names[2].Split('=')[1].Replace("\\", "");
     
            //PublicKeyToken = Names[3].Split('=')[1].Replace("\\", "");
     
            //reference.Path = "~/MyScriptHandler.ashx?Assembly=" + DLLName +
     
            //    "&VersionNumber=" + VersionNumber +
     
            //    "&Culture=" + Culture +
     
            //    "&PublicKeyToken=" + PublicKeyToken +
     
            //    "&ResourceName=" + reference.Name;
     
            return reference;
        }
    }


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