将 HTML 注入服务器控件
如何将 HTML 注入服务器控件?
我正在创建一个日历控件,并有一些与之配套的 javascript/css 。
此外,我有一些 html 代码,这些代码是使用与 JS/CSS 配合使用的正确 ClientID 生成的,我想将其注入到使用“服务器”控件的位置。
例如:
<MyUC:UC1 ID="someUC" runat="server" />
使用 LiteralControls/RegisterClientScriptBlock 包含 CSS/JS,但想知道 HTML 注入到正文中。
这将呈现为我构建的控件以及随之而来的 CSS/JSS/HTML。
我想我可以在 javascript include 中生成 dom 元素,但我想知道如何从服务器端做到这一点。
How do you inject HTML to a server control?
I'm creating a calendar control and have some javascript/css that go with it.
In addition, I have some html code that gets generated with the proper ClientIDs that work with the JS/CSS and I would like to inject this to where the "server" control is used.
For example:
<MyUC:UC1 ID="someUC" runat="server" />
Using LiteralControls/RegisterClientScriptBlock for including the CSS/JS but was wondering about HTML injection to the body.
This would render as the control I've built PLUS the CSS/JSS/HTML that would go with it.
I guess I can generate the dom elements within the javascript include, but I was wondering how I could do it from the server side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
LB:
看看这篇 CodeProject 文章:
使用 ControlInjector 简化 ASP.NET 服务器控件内 HTML 的构建
http://www.codeproject.com/KB/aspnet/ControlInjector.aspx
LB:
Have a look at this CodeProject article:
Simplify the construction of HTML inside ASP.NET server controls using ControlInjector
http://www.codeproject.com/KB/aspnet/ControlInjector.aspx
如果您只需要添加一些额外的标记,则可以使用 LiteralControl 向服务器控件添加一些 HTML。
或者,您可以使用 System.Web.UI.HtmlControls 库在后端生成特定的服务器控件,并以编程方式在服务器控件中创建您想要的 HTML 结构。
If you need to just add some extra markup, you could use the LiteralControl to add some HTML to your server control.
Alternatively, you can use the System.Web.UI.HtmlControls library to generate specific server controls on the back-end, and programmatically create the HTML structure you'd like within your server control.