how to use object tag and embed tag in asp.net?

Dani AI

Generated

was right that object and embed are plain HTML, and ’s post shows the simple client-side use. In an ASP.NET app the same HTML works in .aspx or Razor views, but there are a few practical points worth knowing so embedding behaves reliably and stays maintainable.

When you need server-side control (Web Forms) prefer creating the tag from code or using a server-side container instead of relying on ad-hoc in-page markup. Creating an object or embed programmatically avoids parser quirks and makes attributes easy to set from code-behind:

var obj = new System.Web.UI.HtmlControls.HtmlGenericControl("object");
obj.Attributes["data"] = ResolveUrl("~/media/sample.pdf");
obj.Attributes["type"] = "application/pdf";
obj.Attributes["width"] = "800";
obj.Attributes["height"] = "600";
Placeholder1.Controls.Add(obj);

In ASP.NET MVC / Razor just emit the HTML in the view (or use a TagHelper). Example pattern for dynamic values:

@Html.Raw($"<object data=\"{Url.Content(Model.FilePath)}\" type=\"application/pdf\" width=\"800\" height=\"600\">Fallback message</object>")

Best practices and troubleshooting: prefer HTML5 <video>/<audio> for media when possible. Always set the correct type/MIME, provide fallback content, and check browser console for plugin/CSP errors. For PDFs consider <iframe> or a JS viewer (PDF.js) for more consistent behavior. If embedding third-party content, watch CORS and Content-Security-Policy headers. For reference on element specifics see MDN’s pages for the object and embed elements and Microsoft’s HtmlGenericControl docs: MDN: object element, MDN: embed element, HtmlGenericControl (MSDN).

Recommended Answers

All 2 Replies

how to use object tag and embed tag in asp.net?

same as in html

<embed src="player name">
</embed>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.