在 .NET 中设置 CMS 内容
将数据库中的动态内容设置为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 asp:PlaceHolder 标记,除非使用它们,否则它们不会添加任何 html。
You could use asp:PlaceHolder tags, these don't add any html unless they are utilised.
您可以编写一个自定义类,我将其称为“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.