1

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 my .net appliction files

This is my ASP.NET web app that I want to migrate in Tridion. Please help

AmateurCoder
  • 4,272
  • 3
  • 17
  • 31
  • 2
    Does your page already work outside of Tridion? If not, get that sorted first. If it does work outside of Tridion: what does the page do and how do you want to integrate with Tridion? – Frank van Puffelen May 15 '12 at 14:49
  • it works very well outside the tridion. and the page should handle some page-load events. i want to publish/develop the chatwin.aspx in tridion and include user controls as shown in image(.ascx files). – AmateurCoder May 15 '12 at 14:53
  • 1
    You mentioned "the page should handle some page-load events" twice now. What sort of events do you mean? ASP.NET events? Or Tridion events? – Frank van Puffelen May 15 '12 at 14:56
  • asp.net events such as button click – AmateurCoder May 15 '12 at 15:16
  • 1
    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 van Puffelen May 15 '12 at 15:22
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11268/discussion-between-puf-and-manoj) – Frank van Puffelen May 15 '12 at 15:29
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11285/discussion-between-puf-and-manoj) – Frank van Puffelen May 16 '12 at 01:03

3 Answers3

6

So you have two files for every page in this application:

  1. the ASPX file that contains the markup
  2. 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 van Puffelen
  • 565,676
  • 79
  • 828
  • 807
3

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.

Chris Summers
  • 10,153
  • 1
  • 21
  • 46
  • I think "very bad practice" is overstating it. The ability of people to publish code to your application depends on security settings, and I know of more than one Tridion installation where it would be possible to break the application by publishing the wrong thing from Tridion. Even in mission-critical settings, Tridion is perfectly capable of controlling who does what, and safeguarding the application. On the other hand, I'd agree that this kind of scenario is not mainstream, and for most normal situations, I'd do as you have described. – Dominic Cronin Jan 02 '13 at 22:29
3

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
Will
  • 965
  • 5
  • 19