page_load and event handler for a radiobutton

T

Tony Johansson

Hello!

In the code-behind file I have this event handler
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitPositionRole();
}
}

I have also four event handler in the code-behind file see below. One for
each radio button. All four are in the same Group.
When I change the radio button the event handler is called.

Now to my question. What seems strange here is that the event hadler
Page_Load is called before the event handler for the
radio_button. I have thought that the Page_Load should be called as the last
event handler.
For example if I change the radio button from worker radiobutton to
bossButton the following happen.
1. Page_load will be called.
2. Event handler bossButton_CheckedChanged is called

So can somebody explain why the Page_Load is called as the first event
handler ?

protected void workerButton_CheckedChanged(object sender, EventArgs e)
{
InitPositionRole();
}
protected void bossButton_CheckedChanged(object sender, EventArgs e)
{
positionRole.Items.Clear();
positionRole.Enabled = true;
positionRole.Items.Add("General Manager");
positionRole.Items.Add("Project Manager");
}
protected void vpButton_CheckedChanged(object sender, EventArgs e)
{
positionRole.Items.Clear();
positionRole.Enabled = true;
positionRole.Items.Add("VP Sales");
positionRole.Items.Add("VP Marketing");
positionRole.Items.Add("VP Production");
positionRole.Items.Add("VP Human Resources");
}
protected void presidentButton_CheckedChanged(object sender, EventArgs e)
{
positionRole.Items.Clear();
positionRole.Enabled = false;
}
 
G

Gregory A. Beamer

I have thought that the Page_Load should be called as the last
event handler.

It is late in the cycle, but specific event handlers are called after
Page_Load(). This of it this way: You are "loading" the page into memory to
be sent and the event handlers can alter that "load" before it is sent to
the client.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top