This question is locked. New answers and comments are not allowed.
Anthony Smith
Top achievements
Rank 1
Anthony Smith
asked on 28 Jan 2010, 10:32 PM
Hi guys
I've just dropped the new release into my MVC 2.0 project and it still hasn't fixed some of the problems we have had with the script register from the begining... also before I continue yes I am using the Mvc2 binaries...
Essentially I have a several Editor Templates that need to register scripts that run on document ready... With previous release drops I have had to have something like the following at the top of the editor (note this is what is at the top of my DateTime editor)...
When we originally created the editor, I was just using the "Html.Telerik().ScriptRegistrar().OnDocumentReady(...)" but quickly found it doesn't do anything... Hence I have had to manually register the script which is something I wouldn't have thought I would have to do.
Also because of this, I have to get the jQuery script to register in the head tag and remove the jQuery script from rendering as part of the default group.
I have reported this previously, but I was told that the previous drop didn't support MVC 2 but this release is supposed to support v2.
Cheers
Anthony
I've just dropped the new release into my MVC 2.0 project and it still hasn't fixed some of the problems we have had with the script register from the begining... also before I continue yes I am using the Mvc2 binaries...
Essentially I have a several Editor Templates that need to register scripts that run on document ready... With previous release drops I have had to have something like the following at the top of the editor (note this is what is at the top of my DateTime editor)...
| <%-- NOTE This doesn't currently do anything due to bug --%> |
| <% Html.Telerik().ScriptRegistrar() |
| .OnDocumentReady(() => { %> <%= Html.BuildDataTimeJS(ViewData.TemplateInfo.HtmlFieldPrefix.ToHtmlClassId()) %> <%}); %> |
| <%-- NOTE this should be removed once the telerik bug is fixed and the above used instead --%> |
| <script type="text/javascript" language="javascript"> |
| $(document).ready(function() { |
| <%= Html.BuildDataTimeJS(ViewData.TemplateInfo.HtmlFieldPrefix.ToHtmlClassId()) %> |
| }); |
| </script> |
When we originally created the editor, I was just using the "Html.Telerik().ScriptRegistrar().OnDocumentReady(...)" but quickly found it doesn't do anything... Hence I have had to manually register the script which is something I wouldn't have thought I would have to do.
Also because of this, I have to get the jQuery script to register in the head tag and remove the jQuery script from rendering as part of the default group.
I have reported this previously, but I was told that the previous drop didn't support MVC 2 but this release is supposed to support v2.
Cheers
Anthony
8 Answers, 1 is accepted
0
Kelly Stuard
Top achievements
Rank 1
answered on 28 Jan 2010, 10:43 PM
Where are you rendering the scripts out?
Is it in the top, before the content placeholders, or is it at the bottom of the page?
| <%=Html.Telerik().ScriptRegistrar() %> |
| <%-- or --%> |
| <% Html.Telerik().ScriptRegistrar().Render(); %> |
0
Anthony Smith
Top achievements
Rank 1
answered on 28 Jan 2010, 10:50 PM
Hey thanks for the reply...
My master page looks something like this:
As a side note, if I have any pages, or normal controls or even controls within controls that I render, with the above everything works fine... its just the editor templates that have an issue.
Cheers
Anthony
My master page looks something like this:
| .... |
| <head> |
| .... |
| <%= Html.Telerik().StyleSheetRegistrar() |
| .StyleSheets(sheets => sheets.AddSharedGroup("GeneralCSS"))%> |
| <%-- NOTE this should be removed once bugs are fixed and use the default group instead --%> |
| <%= Html.ScriptJS(Links.Assets.Scripts.jQuery.jquery_1_4_0_min_js)%> |
| </head> |
| <body> |
| ... |
| <%-- Master page javascript stuff --%> |
| <asp:ContentPlaceHolder ID="PreScriptRender" runat="server" /> |
| <%= Html.Telerik().ScriptRegistrar() |
| .Scripts(scripts => scripts.AddSharedGroup("General"))%> |
| </body> |
| </html> |
As a side note, if I have any pages, or normal controls or even controls within controls that I render, with the above everything works fine... its just the editor templates that have an issue.
Cheers
Anthony
0
Kelly Stuard
Top achievements
Rank 1
answered on 28 Jan 2010, 10:56 PM
Your setup is similar to the one I'm currently working on. I have some display templates that I can try it out in to see if I can replicate. If I can't replicate then I'll make an edit template and see if I can replicate.
I can't think of any reason, off-hand, why it would not render. Should be fun. I'll get back to you tomorrow morning; maybe one of the people who works at Telerik will get back to you first.
I can't think of any reason, off-hand, why it would not render. Should be fun. I'll get back to you tomorrow morning; maybe one of the people who works at Telerik will get back to you first.
0
Kelly Stuard
Top achievements
Rank 1
answered on 28 Jan 2010, 11:03 PM
I just put the following in my display template:
And sure enough, it rendered out and I got the alert dialog (twice) when the template loaded in two places.
I don't have time tonight to make an edit template, but I can't imagine it working any different. Something is up. What happens when you add a script reference instead of an onload in the edit template? I'm wondering if all of the script manager is broken in the edit templates; not just the ondocumentload portion.
(BTW: Nice to see that you're using the T4 templates for strong-naming [Links.Assets.Scripts.jQuery.jquery_1_4_0_min_js].)
| <% Html.Telerik().ScriptRegistrar() |
| .OnDocumentReady(() => { %> |
| alert('hi'); |
| <% }); %> |
I don't have time tonight to make an edit template, but I can't imagine it working any different. Something is up. What happens when you add a script reference instead of an onload in the edit template? I'm wondering if all of the script manager is broken in the edit templates; not just the ondocumentload portion.
(BTW: Nice to see that you're using the T4 templates for strong-naming [Links.Assets.Scripts.jQuery.jquery_1_4_0_min_js].)
0
Anthony Smith
Top achievements
Rank 1
answered on 29 Jan 2010, 12:35 AM
Yes I think you are correct in saying that the script manager is broken in the editor template in general... because I forgot to add that I can't add a group from within an editor template... Also I can say is that when I look at the what telerik does render when I try and add something like this is just line return and if I take our the ondocumentready stuff the line break disappears...
Also I'm not sure how you got the display template to pop up the alert as I just created a blank project and tried it again and I got nothing... Maybe I am missing something, below is that I am using and it doesn't work....
When I run the page I get only 2 alerts 'Master' and 'Page'...
Also this is the HTML that is rendered... See the two white spaces which appear in the jQuery(document).ready (if I remove EditorForModel() & DisplayForModel() from index.aspx the extra spaces go away)...
Also I'm not sure how you got the display template to pop up the alert as I just created a blank project and tried it again and I got nothing... Maybe I am missing something, below is that I am using and it doesn't work....
| --\Views\Shared\Site.Master |
| <%@ Import Namespace="Telerik.Web.Mvc.UI"%> |
| <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head runat="server"> |
| <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title> |
| </head> |
| <body> |
| <asp:ContentPlaceHolder ID="MainContent" runat="server" /> |
| <% Html.Telerik().ScriptRegistrar() .OnDocumentReady(() => { %> alert('Master'); <% }); %> |
| <%= Html.Telerik().ScriptRegistrar() %> |
| </body> |
| </html> |
| --\Views\Home\Index.aspx |
| <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> |
| <%@ Import Namespace="Telerik.Web.Mvc.UI"%> |
| <asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server"> |
| Home Page |
| </asp:Content> |
| <asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server"> |
| <%= Html.EditorForModel() %> |
| <%= Html.DisplayForModel() %> |
| <% Html.Telerik().ScriptRegistrar().OnDocumentReady(() => { %> alert('Page'); <% }); %> |
| </asp:Content> |
| --\Views\Shared\DisplayTemplates\Text.ascx |
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> |
| <%@ Import Namespace="Telerik.Web.Mvc.UI"%> |
| <br /> |
| <h1>Display Template</h1> |
| <br /> |
| <% Html.Telerik().ScriptRegistrar().OnDocumentReady(() => {%> alert('Display'); <% }); %> |
| --\Views\Shared\EditorTemplates\Text.ascx |
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> |
| <%@ Import Namespace="Telerik.Web.Mvc.UI"%> |
| <br /> |
| <h1>Editor Template</h1> |
| <br /> |
| <% Html.Telerik().ScriptRegistrar().OnDocumentReady(() => {%> alert('Editor'); <% }); %> |
| --\Controllers\HomeController.cs |
| using System; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Web; |
| using System.Web.Mvc; |
| using MvcApplication3.Models; |
| namespace MvcApplication3.Controllers |
| { |
| [HandleError] |
| public class HomeController : Controller |
| { |
| public ActionResult Index() |
| { |
| this.ViewData.Model = new Test {Name = "Hello World", Id = 12}; |
| return View(); |
| } |
| } |
| } |
When I run the page I get only 2 alerts 'Master' and 'Page'...
Also this is the HTML that is rendered... See the two white spaces which appear in the jQuery(document).ready (if I remove EditorForModel() & DisplayForModel() from index.aspx the extra spaces go away)...
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head><title> |
| Home Page |
| </title></head> |
| <body> |
| <br /> |
| <h1>Editor Template</h1> |
| <br /> |
| <br /> |
| <h1>Display Template</h1> |
| <br /> |
| <script type="text/javascript" src="/Scripts/jquery-1.4.js"></script> |
| <script type="text/javascript"> |
| //<![CDATA[ |
| jQuery(document).ready(function(){ |
| //<<< SPACE HERE - NOTE THIS COMMENT ISN'T PART OF THE RENDER BUT BLANK LINE IS |
| //<<< SPACE HERE - NOTE THIS COMMENT ISN'T PART OF THE RENDER BUT BLANK LINE IS |
| alert('Page'); |
| alert('Master'); }); |
| //]]> |
| </script> |
| </body> |
| </html> |
0
Hi,
I tried to replicate the depicted issue. A test project created in my attempt to replicate the erroneous behavior is attached to this message. Could you please review it and let me know if I am missing something?
Sincerely yours,
Georgi Krustev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I tried to replicate the depicted issue. A test project created in my attempt to replicate the erroneous behavior is attached to this message. Could you please review it and let me know if I am missing something?
Sincerely yours,
Georgi Krustev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Anthony Smith
Top achievements
Rank 1
answered on 01 Feb 2010, 01:58 AM
Hi guys, thanks for the reply...
I tried running the sample project that you provided and it didn't work. Hence, I uninstalled MVC and reinstalled it. When I did this the sample worked as expected.
But when I went to run my sample I now get a null reference exception when ever I try and run the below code... any ideas?
Cheers
Anthony
I tried running the sample project that you provided and it didn't work. Hence, I uninstalled MVC and reinstalled it. When I did this the sample worked as expected.
But when I went to run my sample I now get a null reference exception when ever I try and run the below code... any ideas?
Cheers
Anthony
| Object reference not set to an instance of an object. |
| at System.Web.Mvc.ViewPage.SwitchWriter.Write(String value) |
| at System.Web.UI.HtmlTextWriter.Write(String s) |
| at ASP.views_sportprogram_planquicknavigatepanel_ascx.<>c__DisplayClass3.<__Render__control1>b__2() in d:\Development\PPS\Interface\PPS.Interface.PPSI\Views\SportProgram\PlanQuickNavigatePanel.ascx:line 4 |
| at Telerik.Web.Mvc.UI.ScriptRegistrar.WriteScriptStatements(TextWriter writer) |
| at Telerik.Web.Mvc.UI.ScriptRegistrar.Write(TextWriter writer) |
| at Telerik.Web.Mvc.UI.ScriptRegistrar.Render() |
| at Telerik.Web.Mvc.UI.ScriptRegistrarBuilder.Render() |
| at Telerik.Web.Mvc.UI.ScriptRegistrarBuilder.ToString() |
| at System.Web.HttpWriter.Write(Object obj) |
| at System.Web.Mvc.ViewPage.SwitchWriter.Write(Object value) |
| at System.Web.UI.HtmlTextWriter.Write(Object value) |
| at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\Development\PPS\Interface\PPS.Interface.PPSI\Views\Shared\Site.Master:line 78 |
| at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) |
| at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) |
| at System.Web.UI.Control.Render(HtmlTextWriter writer) |
| at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) |
| at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) |
| at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) |
| at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) |
| at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) |
| at System.Web.UI.Page.Render(HtmlTextWriter writer) |
| at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) |
| at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) |
| at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) |
| at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) |
| at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) |
| <% Html.Telerik().ScriptRegistrar() |
| .OnDocumentReady(() => { %> alert('Control') <%}); %> |
0
Hi Anthony Smith,
I think the problem is the one described in this thread. If this is the case I am afraid we cannot provide a solution right now.
Regards,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I think the problem is the one described in this thread. If this is the case I am afraid we cannot provide a solution right now.
Regards,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.