03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sk<strong>in</strong>s x 247<br />

3. In the Extension box, type sk<strong>in</strong> <strong>and</strong> then from the Editor drop-down list, choose User<br />

Control Editor.<br />

4. Click the Add button <strong>and</strong> then click the OK button to dismiss the Options dialog box.<br />

From now on, you’ll get IntelliSense <strong>in</strong> sk<strong>in</strong> files (you may need to reopen exist<strong>in</strong>g sk<strong>in</strong> files first if<br />

you already created one). With this sett<strong>in</strong>g on, you may get a warn<strong>in</strong>g <strong>in</strong> the Error List about build<br />

providers when you have a sk<strong>in</strong> file open. You can safely ignore this warn<strong>in</strong>g, because sk<strong>in</strong>s work<br />

f<strong>in</strong>e at run time even with these sett<strong>in</strong>gs <strong>in</strong> VS.<br />

TRY IT OUT<br />

Creat<strong>in</strong>g a Sk<strong>in</strong> for the Button Control<br />

To effectively use sk<strong>in</strong>s, you should strive to use CssClass attributes as much as possible <strong>in</strong>stead of<br />

apply<strong>in</strong>g <strong>in</strong>l<strong>in</strong>e attributes that all end up <strong>in</strong> the f<strong>in</strong>al HTML of the page, <strong>in</strong>creas<strong>in</strong>g its size <strong>and</strong> load<br />

time. However, to show you how it works <strong>in</strong> case you do have a special need to add <strong>in</strong>l<strong>in</strong>e attributes,<br />

this exercise shows you how to apply both.<br />

1. In the Monochrome theme folder, add a new sk<strong>in</strong> file <strong>and</strong> call it Button.sk<strong>in</strong>. You add the file by<br />

right-click<strong>in</strong>g the Monochrome folder <strong>and</strong> choos<strong>in</strong>g Add Í Sk<strong>in</strong> File. In the dialog box that follows,<br />

type Button as the filename <strong>and</strong> click OK.<br />

2. Delete the entire contents from the file <strong>and</strong> type the follow<strong>in</strong>g code:<br />

<br />

Note that this markup uses a comb<strong>in</strong>ation of <strong>in</strong>l<strong>in</strong>e attributes for styl<strong>in</strong>g (the BackColor) <strong>and</strong> the<br />

CssClass to po<strong>in</strong>t to a selector <strong>in</strong> your CSS file. Also note that this control does not have an ID<br />

attribute. As expla<strong>in</strong>ed earlier, you can ignore the warn<strong>in</strong>g about miss<strong>in</strong>g build providers because<br />

your sk<strong>in</strong> files will work f<strong>in</strong>e at run time. As soon as you close the sk<strong>in</strong> file, the warn<strong>in</strong>g goes<br />

away.<br />

3. Open the Monochrome.css file from the theme folder <strong>and</strong> add this CSS selector at the end of the<br />

file:<br />

.MyButton<br />

{<br />

color: White;<br />

}<br />

4. Create a new Web Form <strong>in</strong> the Demos folder <strong>and</strong> call it Sk<strong>in</strong>sDemo.aspx. Make sure you base it on<br />

the exported MyBasePage template you created earlier. Give the page a Title of Sk<strong>in</strong>s Demo <strong>and</strong><br />

then add a Button by dragg<strong>in</strong>g it from the Toolbox <strong>in</strong>to the cpMa<strong>in</strong>Content area of the page. You<br />

end up with this code:<br />

<br />

<br />

<br />

5. Save all changes <strong>and</strong> then request Sk<strong>in</strong>sDemo.aspx <strong>in</strong> the browser. If necessary, switch to the<br />

Monochrome theme. The button you added <strong>in</strong> step 4 should now have a blue background with<br />

white text on it. If the changed colors don’t show up, make sure you selected the right theme <strong>in</strong><br />

the drop-down list <strong>and</strong> that you added the MyButton CSS class to the CSS file of the Monochrome

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!