Each available event for a control is listed on a separate line, and creating a wired up event
handler is as simple as either double-clicking the blank area next to the event name to generate
an event with the default naming scheme (ControlName_EventName) or typing a name and
pressing the Enter key. Figure 1-5 illustrates creating the event handler for the TextBox control.
The end result of using the Properties window to add the protected event handler to the
Page class is a method named TextBox_TextChanged that is wired to the TextChanged event of
the TextBox control. You can add code to this handling routine to announce the state change
of the TextBox control by setting the Text property of the Label2 control on the web form:
protected void Name_TextChanged(object sender, EventArgs e)
{
ChangeLabel.Text = "Textbox changed to " + Name.Text;
}
Visual Studio 2008 provides much cleaner code generation when compared to Visual Studio
.NET 2003. There is no longer a code region named ???Web Form Designer generated code??? present
in the code file. Much of the boilerplate code that existed in ASP.NET 1.1 is no longer present,
which makes developers??™ lives a bit simpler.
The result of all the not-so-hard work to this point is the browser view in Figure 1-6, which
shows what happens when Rob enters his name and selects a polite greeting.
Pages:
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61