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.

Add<strong>in</strong>g Logic to Your User Controls x 301<br />

10. Switch back to the master page <strong>and</strong> change the DisplayDirection from Horizontal to<br />

Vertical. Save your changes <strong>and</strong> refresh the page <strong>in</strong> the browser. The sidebar should now display<br />

the vertical banner, as shown <strong>in</strong> Figure 8-9.<br />

FIGURE 8-9<br />

11. Open the AboutUs.aspx page from the About folder <strong>in</strong> Markup View. If you don’t have that file,<br />

create it first. In the cpMa<strong>in</strong>Content ContentPlaceHolder, add some text describ<strong>in</strong>g you or your<br />

organization <strong>and</strong> the reason you created the site. Switch to Design View <strong>and</strong> drop the Banner<br />

.ascx control from the Solution Explorer onto the design surface, right below the text you just<br />

added. VS detects the user control <strong>in</strong> the master page called Banner1 <strong>and</strong> assigns the ID of Banner2<br />

to the user control you just dropped. Notice how you see four banners <strong>in</strong> Design View; two come<br />

from the Banner control <strong>in</strong> the master page <strong>and</strong> the other two come from the Banner control <strong>in</strong> the<br />

About Us page itself. At run time, two of them will be hidden.<br />

12. Select the user control you just added <strong>in</strong> Design View, open its Properties Grid, <strong>and</strong> set the<br />

DisplayDirection to Horizontal.<br />

13. Save all your changes <strong>and</strong> then press Ctrl+F5 to open the About Us page <strong>in</strong> your browser. In addition<br />

to the banner <strong>in</strong> the right sidebar, you should now also see the horizontal banner appear <strong>in</strong> the<br />

content area.<br />

How It Works<br />

The property called DisplayDirection gives your user control some extra behavior. Pages us<strong>in</strong>g the<br />

control should now set the DisplayDirection like this:<br />

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

Saved successfully!

Ooh no, something went wrong!