Asp.Net Server.Transfer problem with Toolkit ScriptManager - asp.net

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.

Related

Confused why JavaScript Bundling breaks in Web Forms ASP.NET 4.5

I'm working on an application where a previous developer loaded the same script file across many different pages.
<script src="../scripts/helpers.js"></script>
Now I'm trying to load that into the BundleConfig.cs file so it's accessible throughout the site and not referenced on every page. I also have BundleTable.EnableOptimizations = true;
bundles.Add(new ScriptBundle("~/bundles/helpers")
.Include("~/scripts/helpers.js"));
In the Site.Master I'm referencing it (currently in the head, but have tried several places in the body as well) as:
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/helpers") %>
</asp:PlaceHolder>
When I look at the network tab in the Chrome console, it shows that it bundled the file, but none of the functionality is working. I can't seem to figure out why it's working when called on every page, but not when it's bundled once and always there. This is the first time I've worked on a .NET app, so I have definitely been scratching my head on this one.
Not sure why it works this way, mostly because I'm not familiar with ASP.NET. But referencing it in the script manager made it work.
<asp:ScriptManager runat="server" EnablePageMethods="true" >
<Scripts>
<asp:ScriptReference Path="~/bundles/helpers" />
</Scripts>
</asp:ScriptManager>

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

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

Use Ajax ToolKitScriptManager along with ScriptManager

I have a page test.aspx which is inheriting master page.The master page has script manager addeded to it.I am trying to add the rating control availabel in the ajax control toolkit.
So i need to add the line <Ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
But since the script manager is already availabel in master page i cannot add this line to my test page.And if i dont add it will not function.
What should i do?
Is there difference between script manager and toolkitscriptmanager.
How to use both simultaneously?
You can replace the scriptManager in the master page with <Ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/> .This will certainly solve your problem.
First of all: if you use ASP.NET 3.5 and controls from AJAX Control Tookit then you must use the ToolkitScriptManager, rather than the ASP.NET ScriptManager. This limitation according to the fact that toolkit script manager adds updated Ajax scripts and without that most of the controls from Ajax Control toolkit library will not work.
If you using ASP.NET 4.0 (4.5) than you have choice to use ScriptManager or ToolkitScriptManager.
Basically the main feature of the ToolkitScriptManager is that it can combine js resource added to page using ScriptReference collection. These js files should be embedded to assembly and for this Assembly ScriptCombine assembly attribute should be added. The main problem here is that you can't control how scripts are combined and after you will try to combine your own scripts you can have a lot of problems (I had experience using this feature and as a result we rejected combining of our scripts using this approach).
The main point here is that currently standard script manager has ability to combine scripts using composite script collection.

ASP.NET Giving error: Your browser does not support scripts or has been configured not to allow scripts

I'm trying to display an RDL report using the ReportViewer control. I already managed to load my report with some help of SO. But now i'm facing another problem.
The report is loaded, because it shows all the parameter textfields of the report. But when i fill those in then no report results are shown. The exact same params do work when i view the report in my web browser through the ReportServer URL.
I think the problem is because it also displays this error on my ASP.NET page (where i have the ReportViewer control).
Your browser does not support scripts or has been configured not to
allow scripts.
Which is weird, because every other javascript enabled site works perfectly fine for me. I believe this error is thrown because i have a ScriptManager in my ASP.NET page.
I have no idea how to fix this problem. Anyone any idea how to solve this problem?
NOTE:
The error does not appear when i remove the ReportViewer control. I can also execute an alert in a <script> tag. So JS seems to be working.
This is what i have in my page:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>Report</h2
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
Font-Size="8pt" Height="742px" InteractiveDeviceInfos="(Collection)"
ProcessingMode="Remote" WaitMessageFont-Names="Verdana"
WaitMessageFont-Size="14pt" Width="907px">
<ServerReport ReportPath="http://server.com/Product/Dashboards/Product_tool.rdl"
ReportServerUrl="http://server.com/ReportServer" />
</rsweb:ReportViewer>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</asp:Content>
And in my PageLoad:
ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials("user", "pass");
ReportViewer1.Visible = true;
ReportViewer1.ServerReport.Refresh();
The most likely cause for this is that the site is on an address that isn't trusted. Internet Explorer opens sites in zones, and it may have put your development address in an untrusted zone, which disables scripts by default. You can usually see an icon somewhere that indicates this and allows you to add the address to the trusted zone.
Look for an eye icon or a warning icon - depending on the version of Internet Explorer you are using.
You could also fire up another browser and see if it is any different.

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

Resources