≡ Menu

Embed a YouTube Video on an ASP.NET Page

I discovered that a simple copy/paste of embed code from YouTube to an .aspx page does not work. A bit of searching led me to a post on the asp.net forum which describes a simple method using an asp:Label

In your .aspx:

<asp:Label id="something" runat="server"></asp:Label>

In your .aspx.cs:

something.Text = "Embed code from YouTube replacing double quotes for single quotes";

Something worth noting is that we must set the value of our asp:Label prior to the page rendering. I placed mine within Page_Load(). Learn more about the ASP.NET Page Life Cycle for a better understanding of what is happening under the hood when a page is requested.

{ 0 comments… add one }

Leave a Comment