Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > VS 2005..Attaching event handlers

Reply
Thread Tools

VS 2005..Attaching event handlers

 
 
hharry
Guest
Posts: n/a
 
      05-21-2007
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!

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      05-21-2007
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)


hharry wrote:
> 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!
>

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      05-21-2007
also i noticed you don't add the event on postback, which is the only
time it would occur.

-- bruce (sqlwork.com)

bruce barker wrote:
> 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)
>
>
> hharry wrote:
>> 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!
>>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
About Event Handlers, Delegates and Scopes Alex MCSD 6 05-21-2004 01:49 AM
Debug step into event handlers Robert Millman ASP .Net 0 07-29-2003 03:24 PM
wiring up html attribute declared event handlers Oisin Grehan ASP .Net 3 07-15-2003 10:27 AM
Re: crazy event handlers! Trevor Hartman ASP .Net 2 06-26-2003 01:53 AM
Dynamic Buttons and Event Handlers, revisited Boban Dragojlovic ASP .Net 0 06-24-2003 01:51 PM



Advertisments