471,089 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Questions about "Handles BlahBlahBlah" for codebehind

Right now I put my VB code in the aspx pages. I would prefer to use
codebehind, especially many of my VB functions may be shared across
multiple aspx pages.

I've tried a few pages with codebehind by follwing some examples on the
Web and they work just fine.

However, I am scared away from codebehind by such extenstions as
"Handles MyBase.Load", "Handles Button1.Click" and "Handles
MyBase.Init" etc. which we seem to have to add to the signatures of the
Subs or Functions we define.

So, here are my questions:

1. When do we need to add such "Handles BlahBlah" extenstions?

2. Which "Handles XXX" do we add to what kind Subs? What are the
criteria?

Thanks.

May 18 '06 #1
6 1434
It makes no difference whether it's in the CodeBehind or not. It's all just
one class definition. The "Handles" statements indicate that the Sub is an
Event Handler. It handles an event fired by a Control.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Complex things are made up of
lots of simple things.

<an***********@yahoo.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Right now I put my VB code in the aspx pages. I would prefer to use
codebehind, especially many of my VB functions may be shared across
multiple aspx pages.

I've tried a few pages with codebehind by follwing some examples on the
Web and they work just fine.

However, I am scared away from codebehind by such extenstions as
"Handles MyBase.Load", "Handles Button1.Click" and "Handles
MyBase.Init" etc. which we seem to have to add to the signatures of the
Subs or Functions we define.

So, here are my questions:

1. When do we need to add such "Handles BlahBlah" extenstions?

2. Which "Handles XXX" do we add to what kind Subs? What are the
criteria?

Thanks.

May 18 '06 #2
Codebehind or not does seem to have a difference. I never use "Handle
BlahBlah" in my inline aspx pages. But it seems that I must explicitly
say "Handle BlahBlah" in codebehind to handle button clicks for
example. Otherwise, it's not gonna work.

Kevin Spencer wrote:
It makes no difference whether it's in the CodeBehind or not. It's all just
one class definition. The "Handles" statements indicate that the Sub is an
Event Handler. It handles an event fired by a Control.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Complex things are made up of
lots of simple things.

<an***********@yahoo.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Right now I put my VB code in the aspx pages. I would prefer to use
codebehind, especially many of my VB functions may be shared across
multiple aspx pages.

I've tried a few pages with codebehind by follwing some examples on the
Web and they work just fine.

However, I am scared away from codebehind by such extenstions as
"Handles MyBase.Load", "Handles Button1.Click" and "Handles
MyBase.Init" etc. which we seem to have to add to the signatures of the
Subs or Functions we define.

So, here are my questions:

1. When do we need to add such "Handles BlahBlah" extenstions?

2. Which "Handles XXX" do we add to what kind Subs? What are the
criteria?

Thanks.


May 18 '06 #3
Okay, since you know better than me, I'd better just shut up and listen.

--

Kevin Spencer
Microsoft MVP
Professional Numbskull

Complex things are made up of
lots of simple things.

<an***********@yahoo.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
Codebehind or not does seem to have a difference. I never use "Handle
BlahBlah" in my inline aspx pages. But it seems that I must explicitly
say "Handle BlahBlah" in codebehind to handle button clicks for
example. Otherwise, it's not gonna work.

Kevin Spencer wrote:
It makes no difference whether it's in the CodeBehind or not. It's all
just
one class definition. The "Handles" statements indicate that the Sub is
an
Event Handler. It handles an event fired by a Control.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Complex things are made up of
lots of simple things.

<an***********@yahoo.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
> Right now I put my VB code in the aspx pages. I would prefer to use
> codebehind, especially many of my VB functions may be shared across
> multiple aspx pages.
>
> I've tried a few pages with codebehind by follwing some examples on the
> Web and they work just fine.
>
> However, I am scared away from codebehind by such extenstions as
> "Handles MyBase.Load", "Handles Button1.Click" and "Handles
> MyBase.Init" etc. which we seem to have to add to the signatures of the
> Subs or Functions we define.
>
> So, here are my questions:
>
> 1. When do we need to add such "Handles BlahBlah" extenstions?
>
> 2. Which "Handles XXX" do we add to what kind Subs? What are the
> criteria?
>
> Thanks.
>

May 18 '06 #4
That's fine, since you do not want to help anyway.

Kevin Spencer wrote:
Okay, since you know better than me, I'd better just shut up and listen.

--

Kevin Spencer
Microsoft MVP
Professional Numbskull

Complex things are made up of
lots of simple things.

<an***********@yahoo.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
Codebehind or not does seem to have a difference. I never use "Handle
BlahBlah" in my inline aspx pages. But it seems that I must explicitly
say "Handle BlahBlah" in codebehind to handle button clicks for
example. Otherwise, it's not gonna work.

Kevin Spencer wrote:
It makes no difference whether it's in the CodeBehind or not. It's all
just
one class definition. The "Handles" statements indicate that the Sub is
an
Event Handler. It handles an event fired by a Control.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Complex things are made up of
lots of simple things.

<an***********@yahoo.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
> Right now I put my VB code in the aspx pages. I would prefer to use
> codebehind, especially many of my VB functions may be shared across
> multiple aspx pages.
>
> I've tried a few pages with codebehind by follwing some examples on the
> Web and they work just fine.
>
> However, I am scared away from codebehind by such extenstions as
> "Handles MyBase.Load", "Handles Button1.Click" and "Handles
> MyBase.Init" etc. which we seem to have to add to the signatures of the
> Subs or Functions we define.
>
> So, here are my questions:
>
> 1. When do we need to add such "Handles BlahBlah" extenstions?
>
> 2. Which "Handles XXX" do we add to what kind Subs? What are the
> criteria?
>
> Thanks.
>


May 18 '06 #5
re:
That's fine, since you do not want to help anyway.
Please, let's limit our comments to technical issues.

re: But it seems that I must explicitly say "Handle BlahBlah" in codebehind
to handle button clicks for example. Otherwise, it's not gonna work.
Not necessarily.

The VB language supports the "handles" statement -- which allows you to
wire-up the bindings to event handlers on the event handler methods themselves.

Although you can also explicitly wire-up event handlers using the server control
declaration (onclick="button1_click"), VB developers typically expect/prefer
using the Handles keyword instead.

C# as a language doesn't have a concept like the "handles" keyword.
Instead, you must explicitly wire-up event definitions.

i.e., VB developers can use either method but C# developers must explicitly wireup events.

You may set AutoEventWireup="true" for VB.Net.

In VS.Net 200x, this means that you can skip the "Handles ...." statement,
provided the method is named correctly.

E.g., if you have AutoEventWireup set to true, this method in a Codebehind file would handle the
Click Event of the Button Control with ID "Button1" without using onclick="Button1_Click"
declaratively :

Sub Button1_Click(ByVal s As Object, ByVal e As EventArg)
' Look, no Handles
End Sub

If you set AutoEventWireup="false", you would need to add the Handles:

Sub Button1_Click(ByVal s As Object, ByVal e As EventArg) Handles Me.Button1.Click
' Need Handles
End Sub

I hope this makes the issue a bit clearer for you.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<an***********@yahoo.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com... That's fine, since you do not want to help anyway.

Kevin Spencer wrote:
Okay, since you know better than me, I'd better just shut up and listen.

--

Kevin Spencer
Microsoft MVP
Professional Numbskull

Complex things are made up of
lots of simple things.

<an***********@yahoo.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
> Codebehind or not does seem to have a difference. I never use "Handle
> BlahBlah" in my inline aspx pages. But it seems that I must explicitly
> say "Handle BlahBlah" in codebehind to handle button clicks for
> example. Otherwise, it's not gonna work.
>
> Kevin Spencer wrote:
>> It makes no difference whether it's in the CodeBehind or not. It's all
>> just
>> one class definition. The "Handles" statements indicate that the Sub is
>> an
>> Event Handler. It handles an event fired by a Control.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> Professional Numbskull
>>
>> Complex things are made up of
>> lots of simple things.
>>
>> <an***********@yahoo.com> wrote in message
>> news:11**********************@g10g2000cwb.googlegr oups.com...
>> > Right now I put my VB code in the aspx pages. I would prefer to use
>> > codebehind, especially many of my VB functions may be shared across
>> > multiple aspx pages.
>> >
>> > I've tried a few pages with codebehind by follwing some examples on the
>> > Web and they work just fine.
>> >
>> > However, I am scared away from codebehind by such extenstions as
>> > "Handles MyBase.Load", "Handles Button1.Click" and "Handles
>> > MyBase.Init" etc. which we seem to have to add to the signatures of the
>> > Subs or Functions we define.
>> >
>> > So, here are my questions:
>> >
>> > 1. When do we need to add such "Handles BlahBlah" extenstions?
>> >
>> > 2. Which "Handles XXX" do we add to what kind Subs? What are the
>> > criteria?
>> >
>> > Thanks.
>> >
>

May 18 '06 #6
Hey, Juan, thanks a lot for your great education. I now know why I had
to say "handle blah blah". I thought that Kevin was grouchy for
something I said which I don't know, and I did not return to this group
for a while.

I've printed it out.

Thanks again.

Juan T. Llibre wrote:
re:
That's fine, since you do not want to help anyway.


Please, let's limit our comments to technical issues.

re:
But it seems that I must explicitly say "Handle BlahBlah" in codebehind
to handle button clicks for example. Otherwise, it's not gonna work.


Not necessarily.

The VB language supports the "handles" statement -- which allows you to
wire-up the bindings to event handlers on the event handler methods themselves.

Although you can also explicitly wire-up event handlers using the server control
declaration (onclick="button1_click"), VB developers typically expect/prefer
using the Handles keyword instead.

C# as a language doesn't have a concept like the "handles" keyword.
Instead, you must explicitly wire-up event definitions.

i.e., VB developers can use either method but C# developers must explicitly wireup events.

You may set AutoEventWireup="true" for VB.Net.

In VS.Net 200x, this means that you can skip the "Handles ...." statement,
provided the method is named correctly.

E.g., if you have AutoEventWireup set to true, this method in a Codebehind file would handle the
Click Event of the Button Control with ID "Button1" without using onclick="Button1_Click"
declaratively :

Sub Button1_Click(ByVal s As Object, ByVal e As EventArg)
' Look, no Handles
End Sub

If you set AutoEventWireup="false", you would need to add the Handles:

Sub Button1_Click(ByVal s As Object, ByVal e As EventArg) Handles Me.Button1.Click
' Need Handles
End Sub

I hope this makes the issue a bit clearer for you.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<an***********@yahoo.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
That's fine, since you do not want to help anyway.

Kevin Spencer wrote:
Okay, since you know better than me, I'd better just shut up and listen.

--

Kevin Spencer
Microsoft MVP
Professional Numbskull

Complex things are made up of
lots of simple things.

<an***********@yahoo.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
> Codebehind or not does seem to have a difference. I never use "Handle
> BlahBlah" in my inline aspx pages. But it seems that I must explicitly
> say "Handle BlahBlah" in codebehind to handle button clicks for
> example. Otherwise, it's not gonna work.
>
> Kevin Spencer wrote:
>> It makes no difference whether it's in the CodeBehind or not. It's all
>> just
>> one class definition. The "Handles" statements indicate that the Sub is
>> an
>> Event Handler. It handles an event fired by a Control.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> Professional Numbskull
>>
>> Complex things are made up of
>> lots of simple things.
>>
>> <an***********@yahoo.com> wrote in message
>> news:11**********************@g10g2000cwb.googlegr oups.com...
>> > Right now I put my VB code in the aspx pages. I would prefer to use
>> > codebehind, especially many of my VB functions may be shared across
>> > multiple aspx pages.
>> >
>> > I've tried a few pages with codebehind by follwing some examples on the
>> > Web and they work just fine.
>> >
>> > However, I am scared away from codebehind by such extenstions as
>> > "Handles MyBase.Load", "Handles Button1.Click" and "Handles
>> > MyBase.Init" etc. which we seem to have to add to the signatures of the
>> > Subs or Functions we define.
>> >
>> > So, here are my questions:
>> >
>> > 1. When do we need to add such "Handles BlahBlah" extenstions?
>> >
>> > 2. Which "Handles XXX" do we add to what kind Subs? What are the
>> > criteria?
>> >
>> > Thanks.
>> >
>


May 31 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Darren Wooding | last post: by
12 posts views Thread by johnb41 | last post: by
2 posts views Thread by sck10 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.