将 HTML 注入服务器控件

发布于 2024-07-24 22:08:55 字数 433 浏览 6 评论 0原文

如何将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清音悠歌 2024-07-31 22:08:55

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

音盲 2024-07-31 22:08:55

如果您只需要添加一些额外的标记,则可以使用 LiteralControl 向服务器控件添加一些 HTML。

myServerControl.Controls.Add(new LiteralControl("<br />"));

或者,您可以使用 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.

myServerControl.Controls.Add(new LiteralControl("<br />"));

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文