TAILIEUCHUNG - ASP.NET 4 Unleased - p 25

CẢNH BÁO Nếu bạn tạo ra một xử lý sự kiện cho sự kiện AdCreated và bạn có bộ nhớ cache của trang, nội dung do người điều khiển AdRotator cũng lưu trữ. Khi xử lý các sự kiện AdCreated, sử dụng một phần bộ nhớ đệm cache trang để chỉ một phần của một trang và không kiểm soát AdRotator chính nó. | 214 CHAPTER 4 Using the Rich Controls WARNING If you create an event handler for the AdCreated event and you cache the page the content rendered by the AdRotator control is also cached. When handling the AdCreated event use partial page caching to cache only part of a page and not the AdRotator control itself. The page in Listing displays a banner advertisement with the AdRotator control. The page includes an event handler for the AdRotator control s AdCreated event. LISTING @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD script runat server protected void AdRotator1_AdCreated object sender AdCreatedEventArgs e Update Impressions AdId .DefaultValue Id .ToString Change NavigateUrl to redirect page id Id .ToString script html xmlns http 1999 xhtml head id Head1 runat server title AdRotator Track title head body form id form1 runat server div asp AdRotator id AdRotator1 DataSourceID srcAds OnAdCreated AdRotator1_AdCreated Runat server asp SqlDataSource id srcAds ConnectionString Server . SQLExpress Integrated Security True From the Library of Wow eBook Displaying Advertisements 215 AttachDbFileName DataDirectory User Instance True SelectCommand SELECT Id ImageUrl Width Height NavigateUrl AlternateText Keyword Impressions FROM AdList InsertCommand INSERT AdStats AdId EntryDate Type VALUES @AdId GetDate 0 Runat server InsertParameters asp Parameter Name AdId Type int32 InsertParameters asp SqlDataSource div form body html 4 The AdCreated event handler does two things. First it inserts a new record into a database table named AdStats which records an advertisement impression. Second the handler modifies the NavigateUrl so that the user is redirected to a handler named . The AdStats database table looks like this Column Name Data .