Maximizing.ASP.dot.NET.Real.World.ObjectOriented.Development [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Maximizing.ASP.dot.NET.Real.World.ObjectOriented.Development [Electronic resources] - نسخه متنی

Jeffrey Putz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Themes



The theme mechanism introduced in ASP.NET v2.0 is an incredibly easy way to change the entire look of your site programmatically and in a hurry. This system applies style information to your pages via style sheets or control "skin" declarations.Listing 12.9.


Another way is to set the theme at runtime, which enables you to alter the appearance based on user preference, for example. The key to doing this is that the setting of the theme must occur in the Page_PreInit() event handler for the page (this event was added for ASP.NET v2.0).


Listing 12.8 shows the event handler code in the page (either from code-behind or in a code block).


Listing 12.8. Setting a theme programmatically


C#



void Page_PreInit(object sender, EventArgs e)
{
Theme = "bluetheme";
}


VB.NET



Sub Page_PreInit(sender As Object, e As EventArgs)
Theme = "bluetheme"
End Sub


You can also theme an entire site by placing an element in web.config between the system.web elements like this: <pages theme="bluetheme" />


What happens when a theme is set? The page framework looks in /App_Themes for the folder that you specify and scans that folder for style sheet files (.css) and skin files (.skin). We'll talk about skins in a moment. For each style sheet found, an HTML link element is injected in between the page's head tags. The style sheets can be named anything you want, as long as they end in .css. In the previous example, the rendered HTML would include the link element shown in the rendered HTML of Listing 12.9.





In order for these style sheet links to be added to the page, the head tag must have the runat="stylesheet" attribute, so it's processed by the server. You'll need this anyway if you want to programmatically manipulate the page title.


ASP.NET also scans the skin files and applies the control style declarations to every control on the page. Note that these declarations only apply to ASP.NET controls and not to static HTML.



/ 146