创建 ASP.NET 复合控件。如何应用与 SkinID 相关的属性?
我正在创建一个基于 asp:Label 控件的自定义复合控件。我希望能够使标签的默认属性以及添加到控件中的其他属性可换肤。
但是,当我将外观定义添加到主题目录中的 Default.skin 文件,并将控件添加到指定 SkinId 的页面时,我无法弄清楚如何让控件使用 Skinned 属性进行渲染。
附加点:
- 我的自定义控件是在单独的库/dll 中定义的。
- 我添加了一个测试属性,并添加了 [Themeable(false)] 属性。然后我在 .skin 文件中设置该属性。当我尝试查看该页面时,我没有收到任何错误,因此在我看来,.skin 文件未得到应用,或者外观文件中的控件定义与aspx 页面。
从皮肤文件:
<ctrl:ExtendedLabel SkinId="test" runat="server"
Expandable="true" Lookup="true" Required="true"
RequiredCssClass="required" Text="Hello" />
从 aspx 页面:
<ctrl:ExtendedLabel SkinID="test" runat="server"/>
从 web.config:
<pages>
<controls>
<add tagPrefix="ctrl" namespace="MyCompany.WebControls"
assembly="MyCompany.Web" />
</controls>
</pages>
我向控件添加了一个测试属性,将其标记为 [Themeable(false)] 以测试在设置该属性时是否会出现运行时错误皮肤文件。没有错误。
请注意,pages 标签没有 styleSheetTheme 属性。但是,我确实有一个覆盖 StyleSheetTheme 属性的基本页面类,该属性似乎适用于其他所有内容。
如果我将 styleSheetTheme 属性添加到 web.config 中的页面标签中,皮肤内容就会起作用,包括如果我尝试设置非 Themeable 属性,则会出现错误。
有什么区别?如何让它与基本页面类属性代码一起使用?
I am creating a custom composite control based off of an asp:Label control. I'd like to be able to have the label's default properties be skinable as well as additional properties that I add to my control.
But when I add a skin definition to the Default.skin file in my themes directory, and add the control to my page with the SkinId specified, I cannot figure out how to get the control to render with the Skinned properties.
Additional points:
- My custom control is defined in a separate library/dll.
- I added one test property, and added the [Themeable(false)] attribute. Then I set that property in the .skin file. I didn't get any errors when I tried to view the page, so it appears to me that the .skin file is not getting applied or that the control def in the skin file doesn't get matched up with the control def in the aspx page.
From the skin file:
<ctrl:ExtendedLabel SkinId="test" runat="server"
Expandable="true" Lookup="true" Required="true"
RequiredCssClass="required" Text="Hello" />
From the aspx page:
<ctrl:ExtendedLabel SkinID="test" runat="server"/>
From web.config:
<pages>
<controls>
<add tagPrefix="ctrl" namespace="MyCompany.WebControls"
assembly="MyCompany.Web" />
</controls>
</pages>
I added a test property to the control, marked it as [Themeable(false)] in order to test if I'd get the runtime error when setting that property in the skin file. No error.
Notice that the pages tag doesn't have a styleSheetTheme attribute. I do however, have a Base page class that overrides StyleSheetTheme property, which seems to work for everything else.
If I add the styleSheetTheme attribute to the pages tag in web.config, the skin stuff works, including getting the error if I try to set the non-Themeable property.
What's the difference? How can I get it to work with the Base page class property code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你尝试这个时你会得到什么?我刚刚创建了一个简单的测试项目,并且能够在 Web 自定义控件上设置自定义属性。我的步骤是:
加载页面并看到文本“Test Text”,该文本仅存在于 Skin 文件中。
希望我上面的步骤之一是您忘记的,但如果没有,请更新您的问题,详细说明您正在尝试的内容和您所看到的内容。
What are you getting when you try this? I just created a simple test project and was able to skin a custom property on a web custom control. My steps were:
Load the page up and see the text "Test Text", which was only present in the Skin file.
Hopefully one of my steps above will be something you forgot, but if not, please update your question with details on what you are trying and what you are seeing.