13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8: Control Events and Event Handlers 199If you click on the page and the default Page_Load method has been removed from theC# code, a new one will appear. Visual Studio 2008 is pretty smart and knows that if youhave one page-loading event, another would just conflict with it. In a single page-loadingevent function or subroutine, you can enter as many statements as you want, so havingmore than a single event handler for a single event does not make any sense even formultiple statements.Some web controls like the Label do not generate event code when double-clicked inthe Design mode. The Label web control can be a useful information source, and with theright design you may well want labels with events and event handlers. Fortunately, youcan add certain events to virtually any web control if you want. You just don’t do it bydouble-clicking the object in the Design mode, as you will see in the next two sections.Selecting Events in the Properties WindowIn the Design or Split mode, if you select a web control, you can see the available eventsin the Properties window. When you open the Properties window, click the LightningBolt icon. All of the events for the selected web control appear. The following stepsprovide a simple example:1. In a new Web Site add a Label web control to the Design portion while in the Splitmode.2. Select the Label control and open the Properties window.3. Click on the Lightning Bolt icon. You will see a list of all events that can be used withthe Label web control as shown in Figure 8-1.4. Next to the Init event, type LabelEvent as shown in Figure 8-1.When working with web controls and events, do not depend on the “double-click”method in the Design or Split mode. Some web controls that can have events do notgenerate them automatically in <strong>ASP</strong>.<strong>NET</strong> and C# by double-clicking them in the Designwindow. However, working with the Properties window, as soon as you enter an eventname such as LabelEvent as shown in Figure 8-1, the code for both the <strong>ASP</strong>.<strong>NET</strong> andC# portions of the application are automatically coded.

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

Saved successfully!

Ooh no, something went wrong!