ASP.NET 主题皮肤
有没有办法只将皮肤应用于特定类型和特定 ID 的控件?例如,我在整个站点中都有用于显示我们公司电话号码的控件,如下所示:
<asp:Label ID="PhoneLabel" runat="server"></asp:Label>
我想知道是否可以以编程方式设置主题并使用该主题的外观来设置标签的文本属性。
我知道我可以做到这一点,
<asp:Label runat="server" Text="319-867-5309"></asp:Label>
但这将为网站上的所有标签设置文本。我只想设置 ID 为 PhoneLabel 的标签文本。
我也知道 SkinID 属性,但这似乎将我的控件绑定到特定的皮肤,并且不允许我通过应用另一个主题来更改电话号码文本。
难道用主题/皮肤就不可能做到这一点吗?
Is there a way to apply a skin only to controls of a certain type and a specific ID? For instance, I have controls throughout a site used to display our company phone number that look like this:
<asp:Label ID="PhoneLabel" runat="server"></asp:Label>
I'm wondering if I can set the theme programmatically and use a skin for that theme to set the text property of the label.
I know I can do this
<asp:Label runat="server" Text="319-867-5309"></asp:Label>
but that will set the text for all the labels on the site. I only want to set the text for labels with an ID of PhoneLabel.
I'm also aware of the SkinID property but that seems to tie my control to a specific skin and will not allow me to change the phone number text by applying another theme.
Is it just not possible to do this with themes/skins?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只是想显示电话号码(并且希望能够全局更改它),那么以下两种方法可能会更容易:
从 web.config 文件中读取电话号码,例如:
并将电话号码放入web.config 的 appSettings 部分:
从 Label 派生一个类,并在该类中将 Text 属性设置为电话号码(硬编码或从配置中读取等)。然后,每当您想要显示电话号码时,请使用该控件而不是标准的 Label 控件,例如:
将其放入 App_Code:
然后使用该控件显示电话号码:
If you simply want to display the phone number (and want to be able to change it globally), then the following two approaches might be easier:
Read the phone number from the web.config file, e.g:
and put the phone number into the appSettings section of your web.config:
Derive a class from Label, and inside that class set the Text property to the phone number (either hard-coded, or reading from config, etc). Then whenever you want to display the phone number, use that control instead of the standard Label control, e.g:
put this in App_Code:
Then use that control to display the phone number:
是的,可以使用外观文件设置文本,并在不同的主题中使用不同的文本。
假设您的项目中有两个主题:“Theme1”和“Theme2”。在每个主题中,您都有一个名为“Default.skin”的文件。
在您设置的 Theme1/Default.skin 文件
中 在您设置的 Theme2/Default.skin 文件
中 在您设置的 aspx 文件中
如果您想要第一个数字,则在 web.config 或 aspx 页面中将 styleSheetTheme 设置为“Theme1”如果您想要第二个数字,则选择“Theme2”。
--
既然我已经回答了这个问题,我想建议皮肤/主题可能不是最好的方法。还有其他解决方案,例如制作自定义电话号码控件,从基础数据源中提取电话号码或使用资源文件。
Yes, it is possible to set the text using Skin files and to have different text in different Themes.
Let's say you have two themes in your project: "Theme1" and "Theme2". In each theme you have a file called "Default.skin".
In your Theme1/Default.skin file you set
In your Theme2/Default.skin file you set
In your aspx file you set
Either in your web.config or aspx page you set the styleSheetTheme to the "Theme1" if you want the first number and "Theme2" if you want the second number.
--
Now that I've answered the question, I'd like to suggest that Skins/Themes might not be the best way to do this. There are other solutions such as making a custom Phone Number control that pulls the phone number from an underlying data source or using a resource file.
据我所知,你不能用主题和皮肤来做到这一点。无法设置与主题无关的 ID、文本等属性。您只能设置那些在控件类中将 ThemeableAttribute 属性设置为 true 的属性。
http://msdn.microsoft.com/en-us/library/ykzx33wh。 ASPX
You cannot do this with themes and skins as far as I know. Properties that are not Theme related Id, Text, and etc cannot be set. You can set only those properties that have a ThemeableAttribute attribute set to true in the control class.
http://msdn.microsoft.com/en-us/library/ykzx33wh.aspx