How to add Youtube webpart in transformation?

Martin Shin asked on July 6, 2015 16:37

Hi. I need your help.

I try to register YouTube Video webpart in ASCX transformation. Code below

<%@ Register Src="~/CMSWebParts/SocialMedia/YouTubeVideo.ascx.cs" TagName="YoutubeVideo" TagPrefix="webpart" %>
<h2><%# Eval("VideoName") %></h2>
<webpart:YoutubeVideo runat="server" id="YouTubeVideoWebpart" VideoURL="<%# Eval("VideoURL") %>" Width="<%# Eval("VideoWidth")%>" Height="<%# Eval("VideoHeight") %>"  />

But Datalist returns this error message. ~\CMSWebParts\SocialMedia\YouTubeVideo.ascx.cs(30): error CS0103: The name 'ltlPlaceholder' does not exist in the current context

What I do wrong?

I use Kentico 8.2 free.

Martin

Correct Answer

Alexander Kontsevoy answered on July 6, 2015 21:26

Dear Martin, Roman get correct answer. I guess that Macros are not supposed to be resolved on this way. Try do something like this:

<%@ Register Src="~/CMSWebParts/SocialMedia/YouTubeVideo.ascx" TagName="YoutubeVideo" TagPrefix="uc1" %>
<h2><%# Eval("VideoName") %></h2>
<uc1:YoutubeVideo runat="server" id="YouTubeVideoWebpart" VideoURL='<%# ResolveMacros(Eval("VideoURL").ToString())%>' Width='<%# Convert.ToInt32(ResolveMacros(Eval("VideoWidth").ToString())) %>' Height='<%# Convert.ToInt32(ResolveMacros(Eval("VideoHeight").ToString())) %>' FullScreen='true'  />

Best regards, Alexander

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on July 6, 2015 18:44

You don't add webparts in transformations, you add the controls within the webparts in your transformations. So you might have to inspect that webpart and find out what it is doing and replicate it in your transformation.

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on July 6, 2015 19:00 (last edited on July 6, 2015 19:34)

Martin,

You've register your control incorrectly, remove ".cs": <%@ Register Src="~/CMSWebParts/SocialMedia/YouTubeVideo.ascx" TagName="YoutubeVideo" TagPrefix="webpart" %>

Thanks, Roman

0 votesVote for this answer Mark as a Correct answer

Martin Shin answered on July 6, 2015 20:17

Hi Roman. If I delete .cs at end of file I get error with message "[TempITemplate.Template]: The server tag is not well formed."

Dear Brenden, all that I need it register YouTube control in transformation and output youtube video on the page according Datalist formatting.

Martin

0 votesVote for this answer Mark as a Correct answer

Martin Shin answered on July 6, 2015 22:15

Alexander, Your code works for me. Thank you!

Martin

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 6, 2015 22:42

It's not good practice to use a webpart within another webpart. You use the controls because you don't need the additional overhead of another webparts code not to mention your page type or any other code you've written is dependent on that webpart being installed. This is why I suggested looking into the inner-workings of the original webpart.

A good example of this is you install a third party webpart and make a reference to it in another webpart. Now when you need to export your custom webpart you won't have your other 3rd party webpart because of this. So you have to remember to export that as well. Or a better solution would be to use the built-in controls that are already there and you know won't be modified. I'm not saying this is how it has to be, I'm saying it's best practice.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.