Tomasz Sikora
Tomasz Sikora

Reputation: 1767

Html in ASP.NET server control

Is there a way to write pure HTML when i'm developing my ServerControl in ASP.NET?

I want to create my control as .dll file. But when I'm writing my control I can only add HTML tags and attributes in C# in my .cs file.

And so i am forced to use this in my RenderContents() method:

output.RenderBeginTag(...
output.AddAttribute(...
output.RenderEndTag(...

instead of for example:

<div attribute1="value"></div>

is there a workaround of this problem?

Upvotes: 0

Views: 160

Answers (1)

WickyNilliams
WickyNilliams

Reputation: 5308

Unfortunately only user controls (ASCX) allow for this type of approach (delcarative markup) but they cannot be packaged into DLLs. I've always hated this restriction, to me it's a code smell programmatically generating markup, but this is what we must live with!

If you have very static markup you could always put it into a resource file (resx) instead of outputting the HTML programmatically

Upvotes: 2

Related Questions