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.

198<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>Key Skills & Concepts●●●Automatic event generationWorking with Change eventsButton Command eventsThe <strong>ASP</strong>.<strong>NET</strong> controls interact with C# primarily through events. A function (or method)in C# has a name associated with some web control event assignment. This chapter looksfurther into events, exploring how to find what events are associated with a given webcontrol and how they can be used in <strong>ASP</strong>.<strong>NET</strong>/C# applications. Much of the material in thischapter will be familiar because virtually every <strong>ASP</strong>.<strong>NET</strong>/C# application up to this pointin the book has included an event—if nothing more than a Page Load event. However, welook further in this chapter to better use events and the web controls associated with them.Automatic EventsWhenever you open a new web site, the C# portion of the application has a functionbeginning with the lineprotected void Page_Load(object sender, EventArgs e)The name of the method is actually Page_Load, and the event that assigns the namePage_Load is part of C# and <strong>ASP</strong>.<strong>NET</strong> assignment. In other words, the event name is notPage_Load but something else. In this case, it’s a built-in OnLoad event assigned thevalue that Page_Load associated with the page object. Because the name “Page_Load”sounds like an event, often developers just assume it’s an event, but it’s not. It could havebeen named anything—“Hip_Hop,” if the designers so desired.Double-Click in the Design ModeThe main shortcut for generating an event associated with a web control has been todouble-click a web control in the Design mode and to use the default function name thatappears in the C# code. For example, if you double-click a TextBox control, you canexpect to see the C# method beginningprotected void TextBox1_TextChanged(object sender, EventArgs e)

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

Saved successfully!

Ooh no, something went wrong!