This is normal behavior. When you select the dropdownlist item, it posts back, loads the content page first, runs:
Response.Write("Default Town Is: " + Globals.DefaultTown + "<br />");
Here Globals.DefaultTown did not change yet.
Then it goes to rpTowns_SelectedIndexChanged method and changes the Globals.DefaultTown.
This page may help to understand better:Events in ASP.NET Master and Content Pages.
SOLUTION:
1.If there are no side effects, you can move the code to the Masterpage:
protected void drpTowns_SelectedIndexChanged(object sender, EventArgs e)
{
Globals.DefaultTown = Convert.ToInt32(drpTowns.SelectedValue);
Response.Write("Default Town Is: " + Globals.DefaultTown + "<br />");
}
2.Or you can redirect to the same page. In the masterpage:
protected void drpTowns_SelectedIndexChanged(object sender, EventArgs e)
{
Globals.DefaultTown = Convert.ToInt32(drpTowns.SelectedValue);
Response.Redirect(Request.RawUrl);
}
In the content page:
if (!IsPostBack)
{
Response.Write("Default Town Is: " + Globals.DefaultTown + "<br />");
}