如何从数据库运行时设置样式?
我很难找到一个关于如何创建一个从数据库 f.ex 加载其样式属性的网页的漂亮而清晰的解决方案。 按钮的背景色和前景色、字体大小等设置为 Session 对象,然后从那里将每个页面上的它们设置为所需的控件。
我在 Global.asax 中有一个加载器 -> Session_Start 将值从数据库加载到称为“设置”的会话对象。 接下来,我尝试使用主题并在皮肤文件 f.ex 上设置这些属性。
<asp:Button BackColor="<%=((Settings)Session["settings"]).BtnBackColor%>"
以便轻松地在一处更改所有按钮。 但在 ASP.NET 上,无法像服务器控件那样设置属性。
因此,当然有可能在每个网页上我在每个 Web 控件的 Page_Load 方法中设置这些样式,但我不认为这是一个非常强大、高效或简洁的选项。
因此,如果有人对此有任何想法,应该如何完成以便尽可能保持代码的维护和健壮性,我真的很感激您的帮助。
I'm having hard time finding a nice and clear solution on how to create a web page that loads it's style attributes from a database f.ex. button back- and forecolor, font size etc.to a Session object and from there would set them on each page to needed controls.
I have a loader in the Global.asax -> Session_Start which loads the values from db to session object called "settings". Next I tried to use Themes and set those attributes on a skin file f.ex.
<asp:Button BackColor="<%=((Settings)Session["settings"]).BtnBackColor%>"
to make it simple to change all the buttons at one place. But on ASP.NET one can't set attributes like that on server controls.
So there's of course the possibility that on each and every web page I set those styles in the Page_Load method on each web control I have but I don't consider that very robust a, efficient or neat option.
So if someone would have any idea on this, how it should be done so that the maintenance and the robustness of the code preserves as good as possible I really would appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要打开一个数据集或数据读取器,然后将其关联到控制属性。
You need open a dataset or datareader and next associated this to control Attributes.