5

I'm pretty new to Tridion 2011 and I need to create a simple ASCX Control to implement an ASP.NET dynamically generated DropDownList.

I'm a little bit confused about how to create a Compound Template (should I do it?) and a Dynamic Assembly to reach my purpose.

I've created a Component Template with Output "ASCX Web Control" and set it to "Published as a Dynamic Component", but I can't figure out how to add my Code-Behind to it.

Should I publish a specific .ascx.cs page and reference it in my .ascx or is there a more "Tridion" way to do it?

Thank you for your help.

2 Answers 2

7

I would advise against publishing code from Tridion (although it's possible) and instead put all your code in assemblies and deploy them with the application. In your ASCX Dynamic Component Presentation you would then reference the type that represents your code behind.

Since you mention a Tridion ASCX control, it means you are thinking of Dynamic CTs, which create Dynamic CPs. This is in fact a stand alone .ascx file that you need to include in your page using some code similar to a Component Presentation Assembler. I'm not sure that's what you actually want. In Tridion, an ASCX is a form of rendered content that also has some code in it and it can be included on many different pages. If you are more likely to use a programming approach to ASCX (like populating dropdowns from an external db, for example), then probably Tridion ASCX DCP is not the right mechanism.

Word of caution on where you store those ASCX DCPs: make sure they are on file system. Take a look at your cd_storage_conf.xml, to ensure that (http://sdllivecontent.sdl.com/LiveContent/content/en-US/SDL_Tridion_2011_SPONE/task_005JJFGGGD8858699HHFHJF). If published to DB, the code in ASCX won't execute (or the .net life cycle event won't fire).

5

First of all you should decide which is the best technical approach for your requirement. I understand from your question that you just need to show a Drop Down List so I will assume that you just need to add a <asp:DropDownList></asp:DropDownList> entry in your page, then you need to consider 2 things.

  1. Is this Drop Down going to be available for several pages and is going to be updated regularly?
  2. Is this Drop Down just going to appear in a page and it won't change?

if #1 is true then you need to create a Dynamic Template or include the logic to generate the Drop Down in an existing Dynamic Template, in the other side if #2 is true then you need to create a Static Template (Embedded in a Page) or include it in an existing Static Template.

Additionally if you want to use a ASCX Web Control as your output format, it is fine and be aware that Tridion will generate a file with .ascx extension that will be loaded dynamically using the API. ASCX Component Presentations are loaded using the Tridion Content Delivery API, refer to the Tridion User Controls like <tridion:ComponentPresentation></tridion:ComponentPresentation> or to the ComponentPresentationAssembler class.

As a last point in this answer, if you are planning to use Data Bound (Drop Down List) controls inside an ASCX Web Control you will find some technical complication because Tridion loads them using the Page.LoadControl and Render methods which in fact will load controls too late in the ASP .Net Page Life Cycle. Check this article for more details Improving Tridion .Net Controls

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.