Prev | Current Page 45 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

The
???Hello, World??? demonstration sets the Text property for Label1 to a blank string each time the web
form is loaded, to overwrite the Label value that is declaratively set in the .aspx page. The activity
happens in a method named Page_Load that is mapped to the Page object??™s Load event:
protected void Page_Load(object sender, EventArgs e)
{
Resultlabel.Text = "";
ChangeLabel.Text = "";
if (!Page.IsPostBack)
{
UpdateMaster();
LoadDropDownList();
}
DataBind();
}
You can also use the properties exposed by the control to read input from the client browser
during postback on the server side. The Button click event handling routine in the ???Hello, World???
web form reads the Text property of the TextBox control and the Value property of the SelectedItem
property on the DropDownList control to display the greeting to the client of the web browser:
protected void ClickMe_Click(object sender, EventArgs e)
{
Resultlabel.Text =
"Your new message: " + Greeting.SelectedItem.Value + " " + Name.Text + "!";
}
CHAPTER 1 ?–  SERVER CONTROL BASICS 9
Control Methods
The second feature exposed by a server control is a collection of object methods. Functionality
implemented using methods typically goes beyond the features of a property??™s set or get method;
they usually perform a more complex action against the control.


Pages:
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57