How to apply themes to user controls

Source: Internet
Author: User

Q: The user control does not have the "topic" attribute. How can I apply the topic and skin?

A: The user control does not contain the topic attribute, but allows you to specify a topic for the page. In this way, the topic is applied to all controls on the page, and the user control applies the topic of the page.

If a topic contains a CSS file, ASP. NET points to the CSS file. If the style in the CSS file is used in the user control, these styles are also applied.

If the subject uses skin and the user control contains the controls to be applied by the skin, the controls also apply skin. For example, to define the skin of a calendar control, if your user control contains the calendar control, the calendar control in your user control will also apply this skin.

If you want to develop a skin for the user control, you need some skills. First, define a simple user control: mywidget. mywidget contains the message attribute.

<% @ Control Language = "C #" codefile = "mywidget. ascx. cs" inherits = "mywidget" %>
<H1> <% = message %> This attribute must be declared in the class file, but more importantly, the themeable attribute must be added to the control.

Using system;
Using system. Web. UI;

[Themeable (true)]
Public partial class mywidget: system. Web. UI. usercontrol
{
Private string _ message;
Public String message
{
Get {return _ message ;}
Set {_ message = value ;}
}

}

Finally, you need a. Skin file and add register to. Skin to write and use the skin file.

<% @ Register src = "~ /Mywidget. ascx "tagname =" mywidget "tagprefix =" OTC "%>

<OTC: mywidget message = "Sahil looks funny" runat = "server"/>

Now drag the mywidget to the page, and the skin file will define the message attribute (if the page applies the topic)

Address: http://odetocode.com/Blogs/scott/archive/2006/06/26/4679.aspx

And thanksSaucerFairy Guidance

Note: to create a topic for the server control, you must register the Server Control in the. Skin file again. The method is the same as registering the Server Control in the page file.

Example program download .rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.