简体   繁体   English

ASP.NET服务器控件中的Html

[英]Html in ASP.NET server control

Is there a way to write pure HTML when i'm developing my ServerControl in ASP.NET? 当我在ASP.NET中开发ServerControl时,有没有办法编写纯HTML?

I want to create my control as .dll file. 我想将我的控件创建为.dll文件。 But when I'm writing my control I can only add HTML tags and attributes in C# in my .cs file. 但是当我编写控件时,我只能在我的.cs文件中添加C#中的HTML标签和属性。

And so i am forced to use this in my RenderContents() method: 所以我被迫在我的RenderContents()方法中使用它:

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

instead of for example: 而不是例如:

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

is there a workaround of this problem? 有这个问题的解决方法吗?

Unfortunately only user controls (ASCX) allow for this type of approach (delcarative markup) but they cannot be packaged into DLLs. 不幸的是,只有用户控件(ASCX)允许这种类型的方法(delcarative标记),但它们不能打包到DLL中。 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 如果您有非常静态的标记,您可以始终将其放入资源文件(resx),而不是以编程方式输出HTML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM