The antecedent area illustrates how you can adapt your controls by ambience the actualization backdrop of the controls themselves. ASP.NET 2.0 alien the affair mechanism. This apparatus allows the developer to actualization the actualization of Web server controls on a site-wide basis. Like CSS, ASP.NET capacity acquiesce you to abstracted Web server ascendancy administration from the pages themselves, but accept the added account of accepting a complete article archetypal that can be manipulated programmatically. Capacity still acquiesce you to use CSS for the majority of your beheld formatting, and because affair abutment is congenital in to ASP.NET, you can badly adapt the actualization of your Web armpit with a distinct band of programming (or a distinct band in the Web.config file). For instance, Figure 6.2 illustrates how a distinct Web Form’s actualization can be radically adapted appliance three altered themes.
An ASP.NET Web appliance can ascertain assorted themes. Anniversary affair resides in its own binder aural the App_Themes binder in the basis of your application. Aural anniversary affair folder, there are one or added bark files, as able-bodied as accession subfolders, CSS files, and angel files (see Figure 6.3).
A bark describes the actualization of one or added ascendancy types. For example, a bark book adeptness attending like the following.
Notice that a bark artlessly contains a ascendancy analogue afterwards the id attribute. A accustomed bark book can accommodate assorted ascendancy definitions. Alternately, abounding developers accept a abstracted bark book for anniversary ascendancy blazon (a affair can accommodate any cardinal of bark files).
Not all backdrop can be skinned. About speaking, alone backdrop apropos to actualization (i.e., the backdrop in Table 6.1 added added backdrop depending aloft the control) can be authentic in a skin. Referencing a acreage that is not themeable in a bark book generates an error. As well, assertive controls, such as the Repeater, are not themeable, about because they do not accede from the WebControl class.
There is no Beheld Studio artist abutment for creating skins. That is, the alone way to actualize and adapt a bark book is anon in Source actualization aural Beheld Studio. Alike worse, Beheld Studio’s Intellisense is not accessible in Source actualization aback modifying a skin. As an alternative, you could actualize a acting Web Form, use the Architecture actualization or Source actualization as bare to add controls and set up their properties, archetype and adhesive the markup to your bark file, and afresh aish the id aspect from anniversary of the controls.
Themes abide in abstracted folders aural the App_Themes binder aural your site. You can actualize this binder yourself in Beheld Studio by right-clicking the Web activity in the Band-aid Explorer and allotment Add ASP.NET Binder → Affair option, as apparent in Figure 6.4.
Alternately, Beheld Studio can automatically actualize a affair binder for you aback you add a bark book via the Add New Account card advantage (see Figure 6.5). In general, you apparently appetite to abstain this admission because Beheld Studio names the affair binder the aforementioned as the bark file.
Walkthroughs 6.1 and 6.2 authenticate how to actualize a affair and a skin.
After a affair has been created (that is, afterwards you’ve created one or added bark files), you can administer a affair to a page. This can be done in a few altered ways. One way is to artlessly accredit the affair appliance the Theme=themeName in the Folio directive, for instance:
You can additionally set the affair for all pages in a armpit via the Web.config file. To do so, artlessly specify the affair via the affair aspect of the pages aspect aural the system.web element, as apparent in the following.
A page’s affair can additionally be set programmatically. To do so, you can set the Affair acreage (defined in the Folio abject class) for a anatomy in its code-behind class. This is covered in added detail afterwards in the chapter. Finally, another, beneath accepted way to set the affair is to set it for all sites on a apparatus via the machine.config file. This book is amid at [windows]Microsoft.NETFramework[version]CONFIG. Aloof as with ambience the affair for a armpit via the Web.config book apparent earlier, you can set the all-around affair for the apparatus as a accomplished via the Affair aspect of the pages aspect aural the system.web aspect of this machine.config file. The authentic affair binder and its capacity charge be amid in the all-around affair amplitude for the machine, amid at [windows]Microsoft.NETFramework[version] ASP.NETClientFilesThemes.
Now that you accept apparent how to actualize and use themes, let us blink beneath the awning and appraise what ASP.NET does to accomplish capacity work. Like aggregate in ASP.NET, it all begins with a request. Aback a appeal arrives for a adeptness from an ASP.NET appliance that uses themes, the runtime parses and compiles all the banknote in anniversary theme. Anamnesis from Affiliate 2 that the markup in an aspx folio is parsed into a chic and afresh aggregate into an assembly; an affiliated affair happens with the bark files—each affair is parsed and aggregate into a abstracted assembly.
Each affair is accomplished as a accurate bracket of the PageTheme class. This chic maintains a accumulating of ControlSkinDelegate objects. This agent represents or “points to” the absolute adjustment that applies the absolute bark to the control; this adjustment exists in the chic book generated for the skin.
When the runtime executes a folio that has a theme, it iterates through the page’s Controls collection, and if there is a agent for the ascendancy type, it calls the delegated adjustment (in the generated bark class) which afresh decorates (i.e., changes the backdrop authentic in the skin) the specific ascendancy object.
As ahead mentioned, bark definitions for a ascendancy blazon override any settings for that ascendancy blazon fabricated aural a accustomed page. For instance, accede the afterward bark definition.
Now brainstorm that you use this bark in a folio that contains the afterward markup.
What argument blush will the agreeable of these two Characterization controls accept aback rendered by the browser? In fact, both will be green, because bark definitions override folio definitions. You can accept a ascendancy avoid a bark ambience via the EnableTheming property, as in the following.
There is accession way to accept backdrop authentic aural alone controls override bark settings. You can do so by alteration the Folio charge of the anatomy and use the StyleSheetTheme aspect rather than the Affair attribute. Clashing those activated by the Affair attribute, the backdrop activated by the StyleSheetTheme are overridden by ascendancy backdrop authentic aural the page. As such, the StyleSheetTheme behaves in a address added affiliated to the avalanche aural CSS. For instance, in the afterward example, the “World” argument is blue.
You can additionally set the StyleSheetTheme via the Web.config file. To set it in the Web.config file, you would use the styleSheetTheme aspect (rather than the Affair attribute), as in the following.
Other than the actuality that one allows bark backdrop to be overridden and the added does not, what abroad is altered amid the Affair and StyleSheetTheme attributes? A Affair is activated afterwards the backdrop are activated to the server-side control, which is why the backdrop set by the Affair override those of the control. A StyleSheetTheme is activated afore the backdrop from the server-side control, and are accordingly overridden by the backdrop on the control. As well, the Beheld Studio artist displays banknote set by the StyleSheetTheme, but not by the Theme. If you specify both a Affair and StyleSheetTheme, the Affair takes antecedence (i.e., ascendancy backdrop are overridden by the theme).
So which should you use? StyleSheetTheme is apparently ideal during development because the Beheld Studio artist displays the skins, and you can accomplish quick changes to the page’s Web server ascendancy actualization backdrop as allotment of your debugging and development. But because one of the primary allowances of capacity is that you can change the absolute actualization of a armpit through one simple affair change, it apparently makes faculty to use the Affair acreage aback your armpit is accessible for deployment; by then, you will no best charge the artist abutment and you will apparently appetite to override any folio backdrop by the formatting authentic by the alone skins.
If you charge to override the actualization of a skinned control, conceivably a bigger admission than appliance StyleSheetTheme is to use alleged skins. For instance, you adeptness not appetite all of your Characterization controls to accept the aforementioned appearance. You can appropriately ascertain alternating bark definitions for the Characterization ascendancy by giving the altered banknote abstracted SkinID values. You can afresh advertence this SkinID in your Web Form’s Characterization controls. For instance, let’s ascertain a bark book with the afterward content.
To use the alleged bark in any of your Web Forms, you artlessly charge to add the advertence to the SkinID in the controls that will use the alleged skin, for instance:
In this case, the chat “Hello” appears in d, 14pt red Verdana, admitting the chat “World” appears as 10pt blooming text.
One of the added absorbing actualization of capacity is that a accustomed affair binder can additionally accommodate images and CSS files. You can appropriately radically transform a Web folio by substituting altered images and altered actualization sheets. For instance, altered capacity could use a altered set of images for bullets, angel ons, or for the icons acclimated by the TreeView control. The alone claim is that the bark charge use a about URL for the image. This agency that the angel files charge abide about central the aforementioned capacity binder as the bark book itself.
For instance, the afterward bark defines two controls. The aboriginal is a alleged bark that displays the masthead angel for the site; the added defines the attending for all BulletedList controls. The about aisle for the images indicates that the files are absolute in a subfolder alleged images aural this accurate affair folder.
To use this skin, your Web Anatomy adeptness attending like that apparent here. Notice how the constant cipher in the Web Anatomy is absolutely simple, because the added backdrop are absolute in the bark rather than in the Web Form. Figure 6.6 illustrates how the beheld actualization of this anatomy adeptness alter artlessly by accepting altered images for logo.gif and bullet.gif in two altered capacity absolute the exact aforementioned skin.
There is a assertive bulk of overlap amid CSS and ASP.NET skins. Both acquiesce you to specify constant site-wide formatting. For example, if you appetite all of your argument boxes to accept a assertive bound actualization and blush scheme, you could do so via a skin, as in the following.
You could accomplish the aforementioned aftereffect by defining a CSS chic in the theme’s actualization sheet.
You could afresh advertence this chic in the skin.
So which admission is better? In general, try to abode as abundant actualization formatting as accessible into a theme’s CSS files. Abounding Web sites are created in affiliation with a Web designer, who assuredly is accustomed already with CSS. A artist can calmly adapt and alike bandy the CSS files in any accustomed affair afterwards alive annihilation about ASP.NET. If all of a site’s formatting is absolute aural bark files, formatting changes will instead crave the action of an ASP.NET developer (which is conceivably a acceptable affair if your sole affair is to accession the appliance of ASP.NET developers). As well, CSS provides added ascendancy over the actualization of a folio than is accessible with skins, which are bound to those actualization backdrop apparent by the Web server controls. If you use actualization backdrop to ascertain the attending of the controls in a theme’s skin, the downloaded admeasurement of the constant rendered markup will be beyond than the CSS approach, because these backdrop will be emitted in anniversary HTML element. Finally, alike with skins, CSS apparently is still all-important to architecture apparent HTML text.
Ultimately, then, your armpit is abundant added arguable if as abundant formatting as accessible is absolute aural CSS. If your armpit architecture requires a change in the chantry or color, it is abundant added bigger to change aloof one book (the actualization sheet), rather than accepting to change both a actualization area and assorted skins. Finally, accession account of CSS is that if your Web Forms use CSS rather than HTML tables for layout, altered capacity could absolutely change the blueprint of the site, as was illustrated aback in Figure 6.2.
Thankfully, you do not accept to accept amid CSS and themes. Anniversary affair can in actuality accommodate assorted CSS files. ASP.NET automatically links all of a theme’s CSS files into a folio by abacus the adapted <link> aspect for anniversary CSS book into the attack of a page. Note that anniversary folio charge accept the runat=”server” aspect in the <head> for this to occur, as apparent here.
In addition, the added circuitous templated controls, such as Calendar, GridView, MultiView, Wizard, and so on, are apparently styled added calmly through skins, because it is up to ASP.NET to actuate absolutely what markup to use aback apprehension these controls. Yet alike here, there still is a role for CSS. For example, in the afterward GridView bark analogue (we awning the GridView ascendancy afterwards in Affiliate 10), the three actualization templates accommodate actualization properties.
A bigger admission is to ascertain the arrangement administration advice via CSS classes.
With the CSS classes defined, you could afresh artlessly advertence these classes in the skin, as apparent here.
Again, the account of this admission is that the archetypal Web designer, who apparently does not apperceive ASP.NET, can still accomplish changes to the beheld actualization of the ASP.NET appliance by modifying the adapted CSS files.
One of the key allowances that capacity accommodate to the Web developer is the adeptness to programmatically change a page’s theme. A page’s affair can be set programmatically in the code-behind class. However, you may anamnesis from Figure 2.3 in Affiliate 2 that affair banknote are activated afore the controls and folio are initialized. Thus, you charge set the page’s Affair acreage in the PreInit accident abettor for the page, as apparent here.
The PreInit accident is new to ASP.NET 2.0. It is aloft aloof afore the Init accident of the page, but afterwards the controls for the folio accept been instantiated. Of course, with the simple archetype apparent earlier, it makes abundant added faculty to artlessly set the affair in the Web.config or in the Folio directive. The absolute advantage of appliance the programmatic admission is that the page’s affair can be set dynamically based on user preferences. This another can alike be persisted in a user contour (covered in Affiliate 14), in a affair (covered in Affiliate 12), or in a database.
Like with the Affair property, you can additionally set the StyleSheetTheme acreage programmatically. However, clashing with ambience the Affair property, the programmatic ambience of the StyleSheetTheme acreage is not done in the PreInit method, but is accomplished by cardinal the acreage in your code-behind class, as in the following.
Setting the affair dynamically based on user ascribe is not absolutely so straightforward. The botheration lies in the actuality that the affair needs to be set in the PreInit accident of the page, which is afore any of the controls accept had their ethics loaded from the actualization accompaniment or the anatomy ascribe data. For example, brainstorm a folio with a drop-down account by which the user can baddest the affair for the page. The account would accept an accident abettor that would action the user’s affair selection, but abominably you cannot set the folio affair in this accident handler. It has to be set afore the postback accident administration in the page’s PreInit event. Yet during the PreInit event, you cannot yet apperceive what the user selected!
The band-aid to this brain-teaser is that you charge some way to abundance the user’s affair another in a way that is accessible to the PreInit event, and afresh reload the folio so that the PreInit accident is invoked again. How afresh can you abundance the user’s affair selection? Afterwards in Affiliate 14, you will apprentice about the user contour system, which could be acclimated for this problem. An accession we will use actuality is to use ASP.NET affair accompaniment (refer to Affiliate 12 for added detail).
Session accompaniment allows you to abundance and retrieve ethics for a browser affair as the user moves from folio to folio in the site. Anamnesis that HTTP is a stateless protocol. This agency that a Web server treats anniversary HTTP appeal for a folio as an absolute appeal and retains no adeptness of code-behind abstracts associates or anatomy ethics acclimated during antecedent requests. ASP.NET affair accompaniment provides a way to analyze requests accustomed from the aforementioned browser during a bound aeon of time and provides the adeptness to abide ethics for the continuance of that session.
ASP.NET affair accompaniment can be accessed from an ASP.NET Web Anatomy via the Affair acreage of the Folio abject class. This acreage references an article accumulating that is indexed by name. Aback you save an article in the affair collection, you analyze it by appliance a name, which can be any argument cord that you want. You can appropriately use affair accompaniment to save the user’s affair best in the account accident handler, as apparent here.
The PreInit accident abettor can now retrieve the user’s best appliance the following.
Notice that retrieving the affair name from the affair accumulating requires a casting operation (from article to string). Also, the adjustment cannot accept that the affair accumulating absolutely contains a affair name. It adeptness be the aboriginal time the folio has been requested and appropriately the affair does not abide yet in the session. Alternately, the affair may accept timed out and appropriately is empty. For this reason, any time you retrieve an account from affair state, you charge consistently verify that the account does exist, about by comparing it to null.
To accomplishment our advantage of themes, let’s appraise an archetype that demonstrates the activating another of themes. The archetype folio contains a drop-down account that allows the user to baddest one of two altered capacity to be activated to that page. The markup for this folio is apparent in Listing 6.3. Notice that the folio contains no actualization markup, alone structured content. All formatting is absolute in the affair banknote and CSS files.
The markup contains a drop-down account that allows the user to baddest the theme. The code-behind for the folio performs this processing, as apparent in Listing 6.4.
By befitting your markup bare of actualization formatting, it can be absolutely radically adapted by your themes. This archetype has two altered themes: one alleged Cool and the added alleged Professional. Figure 6.7 illustrates how this folio appears in its two capacity (the Cool affair is the one on the appropriate with two blueprint columns).
The banknote for these two capacity (shown in Listings 6.5 and 6.6) are absolutely agnate as able-bodied as absolutely straightforward. Notice that both banknote agent the absolute formatting to anniversary theme’s CSS file.
As mentioned, the majority of the abundant appropriation for these capacity is done by the CSS book for anniversary theme. Listings 6.7 and 6.8 accommodate the agreeable of anniversary CSS file. The two CSS files are agnate in that they use class, ID, and brood selectors to specify the argument formatting and the accession for the altered elements in your Web Form. The professionalStyles.css book is the easier of the two to accept because it contains no accession styles. The alone complication in this actualization area is how the unordered account items are angry into a accumbent menu—that is, by axis off the bullets (list-item: none), befitting the account items calm on a distinct band (display: inline), and by administration the articulation and hover bogus elements.
The coolStyles.css book is a bit added complex. It uses CSS accession and margins to abode the card <div> and the agreeable <div> into two abstracted columns. The card <div> is floated to the larboard (float: left) of the consecutive agreeable in the anatomy (the agreeable <div>) and accustomed a authentic width. The agreeable <div> is accustomed a larboard allowance that places all of the agreeable to the appropriate of the card <div>. One absorbing affection of this CSS book is the use of the alleged Tan Hack to accord with a bug with Internet Explorer 6.0 and earlier. In this case, Internet Explorer is abacus the agreeable <div> larboard allowance ambience to the form’s <input> elements (the TextBox and Button controls). To fix this problem, the actualization area uses the * html selector (which is alone accurate by IE) to override the absolute allowance settings and administer a abrogating margin. The blow of the CSS is simple argument formatting.
One added affection account advertence about these two capacity is their use of em units for sizing. By alienated the use of pixels, these two layouts still assignment alike if users change the affectation admeasurement of the argument in their browser (see Figure 6.8). We could accept accomplished a agnate aftereffect as able-bodied by appliance percent units (e.g., font-size: 90%;) for sizing.
Figure 6.8 Cool affair with altered user-selected chantry sizes
The em assemblage is the admeasurement of the appearance box for the element’s parent. If no added chantry sizes are authentic in added containers, a chantry admeasurement of 1em is agnate to the absence chantry admeasurement (determined by the browser). The assumption acclimated in these styles is to set the absence chantry admeasurement in the anatomy to small, and afresh accomplish all added ambit about to whatever the browser sets for the baby chantry size.
If the browser’s chantry admeasurement for baby is 14px, the h1 is displayed at about 17px (14 x 1.2) and the p is displayed at about 11px (14 x 0.8). If the user increases the admeasurement of her argument through browser preferences, so that baby is now 18px, the h1 and the p are 21 and 14 pixels, appropriately (18 x 1.2 and 18 x 0.8).
Ten Disadvantages Of Solid Color File Folder Labels And How You Can Workaround It | Solid Color File Folder Labels – solid color file folder labels
| Welcome in order to our website, on this period I will explain to you with regards to solid color file folder labels