VS 2005..Attaching event handlers

H

hharry

Hello All,

In VS 2003, I was able to add event handlers in the
InitializeComponent function. In VS 2005, I can no longer see the auto-
generated code.

I tried to add the event handler for a button in the Page_Load event,
bit this did not work.

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.SaveBtn.Click += new
EventHandler(this.SaveChanges);
}
}

Could somebody explain why the event handler doesn't register properly
when added in Page_Load event and what the correct procedure is for
adding event handlers in VS 2005 and if there is a way to view the
auto-generated code in VS 2005 ?


Thanks in advance!
 
B

bruce barker

in vs2005, the form and the code behind are partial classes that are
compiled into one class, instead of using class inheritance. because of
this vs2005 no longer needs the hack of registering its event handles.
event handlers specified in the codebehind, can be accessed from the
form specifiation.

if you want to do your own hookup, it should be done in oninit.

-- bruce (sqlwork.com)
 
B

bruce barker

also i noticed you don't add the event on postback, which is the only
time it would occur.

-- bruce (sqlwork.com)
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top