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

[Solved] Cannot Find Controls in Firefox and Chrome

2 Answers 97 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.
Darren
Top achievements
Rank 1
Darren asked on 02 Jun 2011, 11:17 PM
I am having an interesting issue with accessing the controls on a page.  Below is the code in question:

@section HeadContent{
    <script>
        $(document).ready(function () {
           
            // Disable the fields on load
            var ld = $('#LandingDate').data('tDatePicker');
            alert(ld);
	    
 	    // Other Controls Omitted for brevity . . . 
        });
    </script>   
}  

In IE 8, the alert displays an Object.  In both Chrome 11 and Firefox 3.6.9, the alert displays 'undefined'.  My includes in the header file are shown below:

@Html.Telerik().StyleSheetRegistrar().DefaultGroup(group =>                          
    group.Compress(true).Add("telerik.common.css").Add("telerik.outlook.css"))
<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>

Any ideas what might cause this behavior?

Thanks in advance.

-Darren

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 03 Jun 2011, 07:37 AM
Hello Darren,

 If you check the generated output of your page you will see that all Telerik extensions are initialized in another $(document).ready() call. In most browsers (read everything but IE) the document.ready handlers are executed in the order they appear. Which means that your code will look for the datepicker before it is initialized. I suggest you move your code *after* the ScriptRegistrar declaration so it is always executed after the Telerik components are initialized.

All the best,
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
Darren
Top achievements
Rank 1
answered on 07 Jun 2011, 06:34 PM
Antanas,

Thank you for your reply.  That worked.

For posterity's sake, I added the following to my _Layout.cshtml:

 @Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Compress(true).Combined(true))
 @*Allow document.ready() code to be added*@
 @RenderSection("BottomJavascriptSection", required: false)

I then added the new document.ready() code in a section called "BottomJavascriptSection", as displayed below:

@section BottomJavascriptSection{
    <script>
        // Register the Lost Focus event for the Ticket Number
        $(document).ready(function () {
            
            // Disable the fields on load
            $('#LandingDate').data('tDatePicker').disable();

           // Omitted for brevity . . . 
        });
    </script>   
}

Thanks,

-Darren
Tags
General Discussions
Asked by
Darren
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Darren
Top achievements
Rank 1
Share this question
or