How to Combine Scripts using Telerik ASP.NET with AJAX Control Toolkit - asp.net

I am working on a corporate website where the AJAX Controls are being used in tandem with Telerik ASP.NET Controls. While this poses no real issue in terms of functionality, there is a problem with overall performance.
In order to prevent the AJAX toolkit script manager from making multiple calls for all scripts on every component it supports, we set the CombineScripts flag to true, set the EnablePartialRendering flag to true and specify a URL for the CombineScriptsHandlerUrl.
This works great as the generated Scripts for the AJAX Components are significantly decreased as well as corresponding roundtrips. However, we've found that the Telerik Controls have issues with this setting. More specifically for this particular site (the TelerikHTMLChart Control)
After further research, it was affirmed that the CombineScripts flag has to be set to false in order for the Telerik controls to work with the AJAX controls in this capacity.
Obviously this is not the most ideal option when you're targeting to increase the sites overall response time.
Has anyone having this issue been able to acquire a reasonable solution for the problem that would allow the AJAX and Telerik ASP.NET components to play happily together without performance degradation?

Thank you for the response rdmptn, but while in the process of waiting for someone to respond with an appropriate and acceptable resolution; I managed to figure out the solution to the issue. So I am posting this for others who may also have the concerns for performance and require a viable solution to the problem.
Rdmptn has already done a very fine job proposing workarounds this problem. In fact, the cause of the problem is in fact as has already been stated. However, there is another way to have the AJAX ToolkitScriptManager implemented with the CombineScripts flag set to true to alleviate excessive roundtrips and also use the Telerik Controls in a performance efficient manner. I had to experiment a bit in effort of finding this solution so maybe this will help others. The Telerik support staff was unable to provide this solution, so I am also giving it to them.
First, you have to identify the required Telerik Script references required for your particular scenario. You may acquire this from the following link: http://www.telerik.com/help/aspnet-ajax/introduction-disabling-embedded-resources.html
Then find the Telerik control(s) you need on your site. You will note that the options provided in this link restate the 3rd bullet point provided by rdmptn. However, the method I am describing does not require any modification to the web.config nor does it use CDN references. Our decision to opt out of CDN references is to avoid further potential performance degradation by reliance on other sites.
Once you've identified the control(s) you require, copy and paste the ScriptReferences from the link provided into a tag within the AJAX ToolkitScript Manager. In my case, the resulting code would look like this:
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" ScriptMode="Release" runat="server" EnablePartialRendering="true"
CombineScripts="true" CombineScriptsHandlerUrl="~/AjaxScriptMergeHandler.ashx">
<CompositeScript>
<Scripts>
<asp:ScriptReference Path="~/Scripts/Common/Core.js" />
<asp:ScriptReference Path="~/Scripts/Common/jQuery.js" />
<asp:ScriptReference Path="~/Scripts/Common/jQueryPlugins.js" />
<asp:ScriptReference Path="~/Scripts/Common/HTML5UI/html5/core.js" />
<asp:ScriptReference Path="~/Scripts/Common/HTML5UI/html5/dataviz/core.js" />
<asp:ScriptReference Path="~/Scripts/Common/HTML5UI/Data/html5/data.js" />
<asp:ScriptReference Path="~/Scripts/Common/HTML5UI/html5/userevents.js" />
<asp:ScriptReference Path="~/Scripts/Common/HTML5UI/DataViz/html5/dataviz/themes.js" />
<asp:ScriptReference Path="~/Scripts/Common/HTML5UI/DataViz/html5/dataviz/chart.js" />
<asp:ScriptReference Path="~/Scripts/Common/HTML5UI/DataViz/html5/dataviz/svg.js" />
<asp:ScriptReference Path="~/Scripts/Common/HTML5UI/DataViz/html5/dataviz/vml.js" />
<asp:ScriptReference Path="~/Scripts/HtmlChart/RadHtmlChart.js" />
</Scripts>
</CompositeScript>
</ajaxToolkit:ToolkitScriptManager>
This approach allows the AJAX ToolScriptManager to explicitly minimize the number of Scripts required to support the components you actually use in your site (or webpage) having the CombineScripts tag set to true while simultaneously loading only those Scripts that are required within your application to be loaded for the Telerik controls.
No more being set to false as has been the often response for the noted incompatibility issues; while at the same time loading only the required Scripts to support your Telerik controls. VOILA!
Hope this information helps others and saves them the time we've wasted to get a resolution.
Again, thank you rdmptn for posting your suggestions!

I am not aware of a way to do that. AjaxControlToolkit broke compatibility with <asp:ScriptManager>. Telerik controls are built over the vanilla MS AJAX framework, so there is no compatibility between the two suites due to the AjaxControlToolkit changes in the winter of 2013.
Thus, ideas to consider are:
remove the AjaxControlToolkit controls in favor of the Telerik controls
live with more requests than you would like to
try downloading the combined script for the Telerik controls from their CDN and referencing that in your page, then disabling the embedded scripts for them. You can enable it by using RadSCriptManager, enabling its CDN and setting the Telerik.ScriptManager.TelerikCdn.CombinedScript appSettings key to true in the web.config
if you only need the HtmlChart from Telerik, try the Kendo Chart widget. They are both the same, but the Kendo widged is pure client-side code and is not related to MS AJAX, AjaxControlToolkit or the UI for ASP.NET AJAX suite

Related

Can I publish an ASPX page and its code-behind file from Tridion?

I have developed an ASP.NET chat application. Now I want some integration with my Tridion page. To do so I need some code behind file for the published page. And one more issue suppose I want to add a button in my page with its click event. How can I achieve that?
what I've done :
<%# Page language="c#" Inherits="SDLchat.ChatWin" CodeFile="ChatWin.aspx.cs" %>
<%# Register src="ChatLogin.ascx" TagName="c2" TagPrefix="uc2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ChatWin</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Panel ID="Panel1" runat="server">
<uc2:c2 ID="log2" runat="server" />
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" Visible="False">
<asp:LinkButton ID="LinkButton1" runat="server"
onclick="LinkButton1_Click">Change Room</asp:LinkButton>
</asp:Panel>
</form>
</body>
</HTML>
This is my ASP.NET web app that I want to migrate in Tridion. Please help
So you have two files for every page in this application:
the ASPX file that contains the markup
the CS file that contains the code
Since Tridion publishing is based on one-file-per-page, you can get both of these files published from Tridion by creating two separate pages for them. Alternatively you can choose to just publish the ASPX from Tridion and deploy the CS file when you deploy the web application to IIS.
I'd suggest putting the ASPX contents into a DWT Template Building Block in Tridion and then using that one as the only Building Block in a Compound Page Template.
If you decide to also publish the code-behind CS file from Tridion, create a separate DWT for it, paste the code in there and create a separate Compound Page Template for it.
On your second question about a PageLoad event: Tridion will just publish the files that you put in it in this case. It has nothing to do with the ASP.NET code you put in those files. If the ASP.NET page-load event works outside of Tridion, it'll work when you publish the same files from Tridion.
Frank has made an accurate answer, but I would consider it a very bad practice to publish any code from the CMS to the Web Application. Using that approach makes it impossible to test your entire application as CMS users can incrementally update the application.
I would strongly suggest putting all your code behinds into the web application and deploying those through your typical web application deployment process offered by tools such as Visual Studio, and only publishing the ASPX files which have references to the code which is already in your web application.
I agree with Chris here, just because it is possible to publish just about anything from SDL Tridion CMS (including dlls, .config files, uncompiled code etc. etc.) doesn't mean you should.
The lifecycle of application logic (or code) is very different to the Content life cycle. Typically code changes need to be carefully deployed, tested, fixed and redeployed throughout dev, test, acceptance environments before being deployed on production by technical users in a single action. Depending on your organization you may have monthly or shorter/longer development and deployment cycles.
On the other hand, your real life content typically lives the production environment only and is updated as often as required (perhaps hourly or even more frequently) by non-technical users.
If you confuse Content Management with Application deployment you will quickly get into a mess. Imagine someone accidentally unpublishing the App_Code structure group? What if an editor republishes an entire Structure Group but didnt realize that you were halfway through making some changes to the code behind? How are you going to ensure that the dll in the bin structure group gets published at exactly the same time as the web.config and the ascx controls registered in it which are somewhere else? Best case your application might not work, worst case you get compilation errors throughout your entire site.
Some guidelines that I have seen and used on various ASP.NET/SDL Tridion sites are as follows:
Use a standard base page (or limited set of base pages, perhaps determined by page template) as a common code behind for all your published aspx pages - put generic logic in here
For any specific functionality, encapsulate this in a control (ascx or web control) and put logic in the code for this
Have the .cs for the base page, code behind for controls and other logic in a compiled dll in the bin directory - App_Code is great for development, but can create deployment headaches with all those different files to manage

Asp.Net Server.Transfer problem with Toolkit ScriptManager

I'm working on a site which has a toolkitscriptmanager in the master page. My problem lies when navigating to a page which performs a server.transfer. I'm actually also using url redirects, but from what I can tell, that doesn't have any bearing on the problem.
If I change code to Response.Redirect, the page redirects fine, but that's not the functionality I'm looking for, I need to keep the SEO friendly urls.
For example - say in the code of Page1.aspx there's a Server.Transfer to Page2.aspx. What I've diagnosed, is that the Script Manager adds a script reference to the page your'e browsing. So, If I were to navigate straight to Page2.aspx, The script added is
<script src="/Page2.aspx?_TSM_HiddenField_=ctl00_ctl00_ToolkitScriptManager1_HiddenField... etc
However, with the Server.Transfer, it's trying to find
<script src="/Page1.aspx?_TSM_HiddenField_=ctl00_ctl00_ToolkitScriptManager1_HiddenField... etc
How can I tell the ScriptManager to use the final destination for the script file? I've been researching trying to use some magic setting in the TSM but no luck so far.
After some digging and testing, I was able to get this to work. I had to move my scripts defined in the head into the TSM, and make use of the CompositeScripts:
<act:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" CombineScripts="false">
<CompositeScript>
<Scripts>
<asp:ScriptReference Path="/js/jquery.1.4.2.min.js" />
<asp:ScriptReference Path="/js/jquery-ui.1.8.5.min.js" />
<asp:ScriptReference Path="/js/jlEmbed.js" />
</Scripts>
</CompositeScript>
</act:ToolkitScriptManager>
What I find stringe is if I set CombineScripts=true, the TSM would compile all the js files into its own internal script - and then still place the script referencing the page it's on. By turning CombineScripts=false, it still compiles the js files, does them individually, and also does so for the page script reference.

Trying to use EnableCdn with ScriptManager, not fully working

You can see in the source of this site that some asp.net script files are being served from the microsoft cdn, while a couple others are not: http://www.deadlywind.com .
I'm currently using this in the root master file:
<ajaxToolkit:ToolkitScriptManager runat="Server" EnableScriptGlobalization="true"
EnableScriptLocalization="true"
EnableCdn="true"
LoadScriptsBeforeUI="false"
ID="ScriptManager1"
CompositeScript-ScriptMode="Release" />
On the site I have debug mode turned off in the web.config.
(adding clarification)
It appears that the Microsoft Ajax javascript files are still being served up by my server and not the CDN, via the scriptresource.axd references found in the source of the above mentioned website. My question is, why are these not using the CDN and how should I force them to?
You need to configure CDN URLs using WebResource attribute. For example:
<Assembly: System.Web.UI.WebResource("MyScript.js",
"application/x-javascript",
CdnPath := "http://myCdnServer/js/MyScript.js")>
There can be multiple entries and can be put in any code file (as this being an assembly level attribute) but recommended place for keeping these entries would be global.asax.
EDIT: additional info requested by OP
In .NET 4.0, if you want to use Microsoft provided scripts from CDN then you don't need to make WebResource entries. EnableCdn=True should do the trick but make sure that you are using AJAX Toolkit that supports .NET 4.0 (i.e. Toolkit version 40412). Visit http://www.asp.net/ajaxlibrary/cdn.ashx to get more information and list of files on Microsoft CDN.
For .NET 3.5, you have make CDN entries - you can get the script file list from above link and/or actual page source. Folks also uses script combining and then host the combined script on their own CDN for better performance. Check this link: http://www.hanselman.com/blog/ASPNETAjaxScriptCombiningAndMovingScriptResourceaxdsToStaticScripts.aspx

ASP.NET Application lag after post back

When running my application lately, there is a very long delay after a request is made to the server. When debugging and stepping through, the code finishes quickly and then a dialog comes up, which I'm assuming is the reason for the lag. (I've tried a series of other options including disabling usage of ViewState, disabling debugging, installing IE 8 and reinstalling the Ajax Control Toolkit.
The dialog reads as follows:
Find Source: ExtenderControlBase.cs
Original Location: C:\Users\swalther\Projects\AspNetAjax\Releases\30930\AjaxControlToolkitSource\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs
This is strange, since I am not familiar with any user on this machine named swalther (it was reformatted rather recently) and searching my computer for this folder turns up no results.
As usual, any help would be greatly appreciated.
That reference to swalther refers to the developer who compiled the code in the first place.
Fixed. (Second time I've answered my own question - go figure. I'm creating a database of my bugs :) )
Changed this line:
<asp:ScriptManager ID="scriptManager1" runat="server" EnablePageMethods="true" />
to this:
<ajaxControlToolkit:ToolkitScriptManager ID="scriptManager1" runat="server" />
Looks like you have to use the ajax control toolkit script manager instead of the ASP version.

'AjaxControlToolkit' is undefined Error

I am using the AjaxControlToolkit in VS2005, and it works fine. I do have some issues though, when I go to some pages I have, then click back, I get this JavaScript error:
'AjaxControlToolkit' is undefined
I have searched MSDN forums, and google, and tried many of the solutions, but none have worked. I have tried, EnablePartialRendering="true", and others. Short of rewriting everything and changing the workflow of my application, is there any way to find the root cause of this, or fix it?
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
I got this problme fixed but not by setting CombineScripts="false" but by using the solution described in this post.
There have been some changes in the latest version, due to which you have to use Sys.Extended.UI.BehaviorBase instead of AjaxControlToolkit.BehaviorBase in the registerClass call.
To get around this 'AjaxControlToolkit' is undefined Error, you may also want to ensure that you have CombineScripts set to false in your ToolkitScriptManager configuration. This can be found in your Master page and this solution has worked for me.
<myTagPrefix:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true" SupportsPartialRendering="true" **CombineScripts="false"**>
Note you will want to change myTagPrefix to the tagprefix you are using for AjaxControlToolkit. This is usually defined in asp at the top of an aspx file like this...
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="myTagPrefix" %>
This may be a silly question, but did you double check to make sure you have the toolkit reference at the top of your aspx file?
(Adding from comment for ease of reading)
Try adding this to your web.config
<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="false" enableCaching="false" />
</scripting></system.web.extensions>
Is that a javascript error?
I suppose it has to do with back-button support in the toolkit.
And undefined errors mostly occurs because somehow the script that contains "AjaxControlToolkit" doesn't gets properly loaded.
Thing that come to mind:
The order scripts get loaded, does the Toolkit gets priority?
When there are errors in any of the loaded scripts all the other scripts that hasn't loaded yet will simply be canceled and not gets loaded.
See the outputted HTML of the problem page, find links to all the AXD files and make sure you can download them and see valid javascripts inside.
And if you don't already, get Firefox and Firebug and you should be able to trace to the actual script line that emits the error.
Hope this helps.
As [CodeRot] said you need to ensure you have all the AJAX web.config extensions in place, this is the most commonly missed point when doing ASP.NET AJAX sites (particularly from VS 2005).
Next make sure that you have a ScriptManager on the page (which I'm guessing you do from the "EnablePartialRendering" mention).
Make sure that you are referencing the AjaxControlToolkit version for your .NET version, it is compiled for both .NET 2.0 and .NET 3.5, and I believe the latest release is only supporting .NET 3.5.
Ensure that you're getting the Microsoft AJAX Client Library added to the page (that you're not getting any errors about "Sys" missing).
Ensure that you a registering the AjaxControlToolkit in either your ASPX, ASCX or web.config.
If nothing still hasn't worked out for you. Verify that you are not caching this ascx/aspx. Remove the OutputCache declaration.

Resources