在 .NET 中设置 CMS 内容

发布于 2024-09-26 22:23:50 字数 352 浏览 0 评论 0原文

将数据库中的动态内容设置为 aspx 页面中的控件的最佳方法是什么?

我的数据库由页面(index.aspx、home.aspx 等)组成,页面又由控件(DivStart、LabelDescription 等)组成。

我想到的第一个技术是循环遍历页面中的所有控件,查找具有特定类的控件,例如“Cms_DivStart”,然后从名为“DivStart”的数据库控件设置该控件的内部 html 。问题是只显示运行服务器控件,我不想让所有控件都在服务器端。

我可以将页面的所有动态文本存储在隐藏变量中,并在页面加载时使用 jQuery 设置它,但这会使文本不会直接显示。

任何其他想法将不胜感激。

谢谢 /安德烈亚斯

What would be the best approach to set dynamic content from the database to controls in an aspx page?

My database consists of pages (index.aspx, home.aspx and so on) which consists of controls (DivStart, LabelDescription, and so forth).

The first technique that came to my mind was looping through all the controls in the page, looking for controls that have a certain class, e.g. "Cms_DivStart", and would then set the inner html for that control from the database control called "DivStart". The problem is only runat server controls shows up, and I don't want to make all controls server side.

I could store all the dynamic texts for a page in hidden variables and set it with jQuery when the page has loaded, but that would make the text not show up directly..

Any other ideas would be greatly appreciated.

Thanks
/Andreas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

留一抹残留的笑 2024-10-03 22:23:50

您可以使用 asp:PlaceHolder 标记,除非使用它们,否则它们不会添加任何 html。

You could use asp:PlaceHolder tags, these don't add any html unless they are utilised.

旧时浪漫 2024-10-03 22:23:50

您可以编写一个自定义类,我将其称为“CustomPage”,它继承 System.Web.UI.Page 类。然后您的页面就可以继承“CustomPage”。在此类中,添加方法来检索数据、设置自定义属性并在可用控件中显示内容。

You can write a custom class, I'll call it "CustomPage", that inherits the System.Web.UI.Page class. Then your pages can inherit "CustomPage". In this class, add methods to retrieve data, set custom properties and display your content in the available controls.

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