This is a migrated thread and some comments may be shown as answers.

Hijacking Of OnDocumentReady

5 Answers 201 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Steve
Top achievements
Rank 1
Steve asked on 01 Jun 2010, 04:43 PM
I have noticed I can't use the default jquery documentready with using Telerik MVC ? 

The problem with this is that I have my own custom controls (html helpers) that initialize on document ready - ie. my own customer masking controls.

Additionally  - I do not want to put my script inside my aspx/ascx

Is is possible today to tell Telerik not to hijack the document ready of jQuery ?

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 01 Jun 2010, 05:11 PM
Hi Steve,

You can still use $(document).ready. There are two ways to do so:
  1. Make the ScriptRegistrar not to include jquery by calling the jQuery(false) method and use $(document).ready as you would normally do:
    <%= Html.Telerik().ScriptRegistrar().jQuery(false) %>
    <script type="text/javascript">
         $(document).ready(function() {
                 alert('ready');
          });
    </script>
  2. Use any overload of the provided OnDocumentReady method of the ScriptRegistrar object:
  • <%= Html.Telerik().ScriptRegistrar().OnDocumentReady("alert('ready')") %>
  • <% Html.Telerik().ScriptRegistrar()
           .OnDocumentReady(() =>
           { %>
                alert('ready');
             <%
           })
           .Render();
    %>
Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Steve
Top achievements
Rank 1
answered on 01 Jun 2010, 05:49 PM
Not sure though I think this is correct.

ie.

On site.master - I am using Telerik Menu (and on some pages, I am using Telerik datepicker)

Additionally, on those pages I have my own customer html controls that use jQuery (programmatically they render the javascript and html)

If I turn off jQuery - does that mean the menu and datepicker won't work ?

Some clarification needed.
0
Atanas Korchev
Telerik team
answered on 02 Jun 2010, 06:41 AM
Hi Steve,

No, it just means that you have to include jquery by yourself.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Walter Lounsbery
Top achievements
Rank 1
answered on 13 Aug 2010, 06:55 PM
I'm afraid I don't understand why software that used to avoid using jQuery(document).ready() now hijacks that function and has a neat feature to turn off the hijacking and the jquery load so we get to comb through all our code and adjust everything to this change.

Please register me as a dissatisfied customer of the Premium package.  I buy your software so that it does not break code when I upgrade.  You have disappointed me.

I am discovering that the ScriptRegistrar call in the Master page raises a duplicate Render call error when the ScriptRegistrar().OnDocumentReady() "override" is used to cure the problem.  So now I am wasting loads of time chasing your little update.

I also don't understand why we haven't gotten a Q2 release of MVC controls.  Is this line of software being discontinued?  If it looks like it won't be supported, I will be forced to go to other solutions and I won't be looking back.
0
Atanas Korchev
Telerik team
answered on 16 Aug 2010, 07:47 AM
Hi Walter Lounsbery,

I think there is some misunderstanding here. I will explain what the ScriptRegistrar does with regards to document.ready

Telerik Extensions for ASP.NET MVC have always used  $(document).ready to initialize the client-side component. This cannot be changed as this is the right time to initialize a component. To embed code in our own document.ready handler you can  use OnDocumentReady. If you don't want to - nothing prevents you from wiring up document.ready in your own code. Just make sure the jquery JavaScript is included before your script tag. Otherwise you will end up with a JavaScript error. This can be achieved by putting your script tag *after* the ScriptRegistrar which is rendered or by including manually the jquery JavaScript which then needs to disable the automatic including from the ScriptRegistrar by calling jQuery(false).

We have introduced the feature to disable the automatic including of jquery because quite a few 3rd party plugins do not work unless jquery and their own JavaScript files are not included within the HEAD tag of the page. Since the ScriptRegistrar must appear after all Telerik extensions jQuery's javascritp may appear too late.

The duplicate Render exception occurs if you render twice any Telerik UI component. In order to use multiple script registrars you should render only one of them. Here is an example:

Site.master:
// "Master" script registrar
<%= Html.Telerik().ScriptRegistrar() %>

Index.aspx

// "Child" script registrar which is not output
<% Html.Telerik().ScriptRegistrar().OnDocumentReady(() =>
{
   %>
         alert('Child ScriptRegistrar');
    <%
}); %>

Atanas Korchev
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Steve
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Steve
Top achievements
Rank 1
Walter Lounsbery
Top achievements
Rank 1
Share this question
or