Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > Control JavaScript Ajax Calls for Same Script Multiple Times

Not answered Control JavaScript Ajax Calls for Same Script Multiple Times

Feed from this thread
  • Nick avatar

    Posted on Apr 27, 2012 (permalink)

    We are currently allowing the controls make Ajax calls to retrieve their respective scripts.  For the most part, this has worked as desired.

    On a particular page we have, the controls are making multiple Ajax calls for the same scripts.  One of the controls on the page, the ComboBox, is malfunctioning due to this.  It does not allow the user to click the arrow to see the drop-down options.  Attempting to input a value will result in the "AutoComplete" options to display.

    When I do not use Ajax to reference the scripts (when I add them through he ScriptRegistrar) the ComboBox works fine.

    Please let me know if you need any more information.

    Thanks.

    Reply

  • Daniel Daniel admin's avatar

    Posted on May 2, 2012 (permalink)

    Hello Nick,

    I am not sure if understand correctly the exact scenario. Could you provide the code you are using or a small runnable project that reproduces the problem so I can check the setup?

    Greetings,
    Daniel
    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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.

    Reply

  • Nick avatar

    Posted on May 4, 2012 (permalink)

    I think I may have thought of the cause of the issue I am having.

    We are currently using the following that is generated by the Telerik control to get the Telerik scripts we need:

    if(!jQuery.telerik) {
    jQuery.ajax({
    url:"/Relative/Path/telerik.common.min.js",
    dataType:"script",
    cache:false,
    success:function(){
    jQuery.telerik.load(...);
    }}); } else {
    jQuery.telerik.load(...);
    }

    I believe what is happening is that jQuery.telerik.load(...) inside the success function is not being executed before the next time if(!jQuery.telerik) { ... } is hit for another Telerik control.  Therefore it makes multiple Ajax requests for the same Telerik scripts.

    Do you have a recommended solution for this?

    Thanks.

    Edit:

    Always referencing the telerik.common script resolves the issue with the same script being retrieved multiple times.  I am still having an issue with the ComboBox when I always reference the telerik.common script.  The ComboBox works fine if I do this:

    helper.Telerik().ScriptRegistrar().DefaultGroup(group => group
                            .Add("telerik.common.min.js")
                            .Add("telerik.combobox.min.js")
                            .Add("telerik.list.min.js"));

    Reply

  • Daniel Daniel admin's avatar

    Posted on May 7, 2012 (permalink)

    Hello again Nick,

    The telerik.common.js file should be included initially before loading the partial view. This is needed in order for an array that keeps the names of the loaded scripts to be created.
    What problems are you experiencing when the telerik.combobox.js and telerik.list.js aren't included initially? Since the Q2 2011 release the scripts should be loaded automatically when the Controls are loaded in partial view via Ajax.


    Greetings,
    Daniel
    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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.

    Reply

  • Nick avatar

    Posted on May 7, 2012 (permalink)

    Thank you for reply Daniel.

    I believe that we are currently using Q3 2011's scripts as the scripts folder we use is 2011.3.1115.  In the next week or two, we will be updating the scripts to a licensed version (I am not sure what specific version, however).

    The issue with the ComboBox when telerik.combobox.js and telerik.list.js are not included initially is that clicking on the arrow to display the drop-down list options does not do anything.  I can, however, type in text to bring up matches in the drop-down.

    The telerik.combobox.js and telerik.list.js scripts are being retrieved via Ajax.

    Reply

  • Daniel Daniel admin's avatar

    Posted on May 8, 2012 (permalink)

    Hi Nick,

    I couldn't reproduces the described behavior on my side. I am attaching a sample project that loads ComboBoxes in partial view via Ajax. Could you check it and tell me if I am missing something?


    Greetings,
    Daniel
    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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
    Attached files

    Reply

  • Nick avatar

    Posted on May 8, 2012 (permalink)

    I do not think that you forgot anything.  The telerik.common.js script is a resource on page load and then telerik.combobox.js and telerik.list.js are being retrieved via Ajax.  That is exactly what our program is doing.

    We have a process of adding GUIDs to the id attribute of fields including the ComboBox.  I will debug the Telerik JavaScript files in hopes of finding the reason why the ComboBox does not operate as it should.

    Thanks again for the help.

    EDIT:

    I do see one difference now.  We have actually moved on to use jQuery 1.7.1 and so we never reference jQuery 1.6.4, which is what the Telerik scripts from 2011.3.1115 use.  Someone made manual changes to the Telerik scripts so that we would hopefully be able to use jQuery 1.7.1 instead of jQuery 1.6.4.  That discrepancy might be causing the issue.

    Before moving further, I think I will just wait until we move on to use the licensed scripts (I am not sure which version we will be using).  I will post back here after that.

    Reply

  • Ben Jensen avatar

    Posted on Dec 13, 2012 (permalink)

    If you add more than one of either kind, only the first combo of each type 
    will work
    
    
    
    @(
        Html.Telerik().ComboBox()
            .Name("ServerBound")
            .BindTo(Model)
    )
    @(
        Html.Telerik().ComboBox()
            .Name("ServerBound")
            .BindTo(Model)
    )
     
    @(
        Html.Telerik().ComboBox()
         .Name("AjaxBound")
         .DataBinding(binding => binding.Ajax().Select("AjaxSelect""Home"))
    )
     
    @(
        Html.Telerik().ComboBox()
         .Name("AjaxBound")
         .DataBinding(binding => binding.Ajax().Select("AjaxSelect""Home"))
    )

    Reply

  • Ben Jensen avatar

    Posted on Dec 13, 2012 (permalink)

    Figured out that you have to have unique names, then it works great

    @(
        Html.Telerik().ComboBox()
            .Name("ServerBound")
            .BindTo(Model)
    )
     
    @(
        Html.Telerik().ComboBox()
            .Name("ServerBound2")
            .BindTo(Model)
    )
     
    @(
        Html.Telerik().ComboBox()
            .Name("ServerBound3")
            .BindTo(Model)
    )

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > Control JavaScript Ajax Calls for Same Script Multiple Times