By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

What is thre difference between OnClick and Click events?

P: n/a
kai
Hi,
In ASP.NET , what is the difference between OnClick and Click events for a
button? Because we have button click event, it can trigger events, why we
still need OnClick?

Please help.

Thanks

kai

Dec 28 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
OnClick is the method while Click is the event. In essence, they are the
same. The difference is in the execution.

If you set the OnClick attribute in your Button tag in the ASPX page, then
the event is automatically generated when the ASPX is compiled when the
AutoEventWireup attribute in the Page directive is set to true. For
example,

<asp:Button id="btnOne" runat="server" Text="Click Me!"
OnClick="btnOne_Click" />

On the other hand, if you do not set the OnClick attribute, you can always
define the Click event as long as you set the AutoEventWireup attribute in
the Page directive to false. In your code-behind, you would most likely do
something like this (in C#):

void Page_Init(Object objSender, EventArgs evtArgs)
{
...
btnOne.Click += new EventHandler(btnOne_Click);
...
}

For both, you have to create the method btnOne_Click:

void btnOne_Click(Object objSender, EventArgs evtArgs)
{
...
}

Hope this helps!
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"kai" <ka******@earthlink.net> wrote in message
news:cN****************@newsread3.news.atl.earthli nk.net...
Hi,
In ASP.NET , what is the difference between OnClick and Click events for
a button? Because we have button click event, it can trigger events, why
we still need OnClick?

Please help.

Thanks

kai

Dec 28 '05 #2

P: n/a
Thanks for Christopher 's inputs.

Hi Kai,

As Christopher has mentioned, OnXXX (suppose XXX is event name), is a
method of a certain control which can be override by derived class while
XXX is the event defined in the control...

Genearlly, when a certain event is to be fired, the control will call its
OnXXX method, and the base class's implementation will call all the event
handlers registered for that event ...... So for OnXXX method, we can
override it if we're developing a certain control or a derived one from
existing control.... While as for event handler, it provide the means
for ther control's user (page developer ) to hook the event and inject
some custom code when the event got fired......

Hope this is what you're wondering...

If there're anything we didn't quite get or anything else we can help,
please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Christopher Reed" <ca****@nospam.nospam>
| References: <cN****************@newsread3.news.atl.earthlink.n et>
| Subject: Re: What is thre difference between OnClick and Click events?
| Date: Tue, 27 Dec 2005 23:21:03 -0600
| Lines: 52
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <ef*************@TK2MSFTNGP14.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip68-106-67-38.lu.dl.cox.net 68.106.67.38
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:367244
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| OnClick is the method while Click is the event. In essence, they are the
| same. The difference is in the execution.
|
| If you set the OnClick attribute in your Button tag in the ASPX page,
then
| the event is automatically generated when the ASPX is compiled when the
| AutoEventWireup attribute in the Page directive is set to true. For
| example,
|
| <asp:Button id="btnOne" runat="server" Text="Click Me!"
| OnClick="btnOne_Click" />
|
| On the other hand, if you do not set the OnClick attribute, you can
always
| define the Click event as long as you set the AutoEventWireup attribute
in
| the Page directive to false. In your code-behind, you would most likely
do
| something like this (in C#):
|
| void Page_Init(Object objSender, EventArgs evtArgs)
| {
| ...
| btnOne.Click += new EventHandler(btnOne_Click);
| ...
| }
|
| For both, you have to create the method btnOne_Click:
|
| void btnOne_Click(Object objSender, EventArgs evtArgs)
| {
| ...
| }
|
| Hope this helps!
| --
| Christopher A. Reed
| "The oxen are slow, but the earth is patient."
|
| "kai" <ka******@earthlink.net> wrote in message
| news:cN****************@newsread3.news.atl.earthli nk.net...
| > Hi,
| > In ASP.NET , what is the difference between OnClick and Click events
for
| > a button? Because we have button click event, it can trigger events,
why
| > we still need OnClick?
| >
| > Please help.
| >
| > Thanks
| >
| > kai
| >
| >
| >
|
|
|

Dec 28 '05 #3

P: n/a
kai
Christopher,
Thanks!!!
Kai
"Christopher Reed" <ca****@nospam.nospam> wrote in message
news:ef*************@TK2MSFTNGP14.phx.gbl...
OnClick is the method while Click is the event. In essence, they are the
same. The difference is in the execution.

If you set the OnClick attribute in your Button tag in the ASPX page, then
the event is automatically generated when the ASPX is compiled when the
AutoEventWireup attribute in the Page directive is set to true. For
example,

<asp:Button id="btnOne" runat="server" Text="Click Me!"
OnClick="btnOne_Click" />

On the other hand, if you do not set the OnClick attribute, you can always
define the Click event as long as you set the AutoEventWireup attribute in
the Page directive to false. In your code-behind, you would most likely
do something like this (in C#):

void Page_Init(Object objSender, EventArgs evtArgs)
{
...
btnOne.Click += new EventHandler(btnOne_Click);
...
}

For both, you have to create the method btnOne_Click:

void btnOne_Click(Object objSender, EventArgs evtArgs)
{
...
}

Hope this helps!
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"kai" <ka******@earthlink.net> wrote in message
news:cN****************@newsread3.news.atl.earthli nk.net...
Hi,
In ASP.NET , what is the difference between OnClick and Click events for
a button? Because we have button click event, it can trigger events, why
we still need OnClick?

Please help.

Thanks

kai


Dec 28 '05 #4

P: n/a
kai
Hi, Cheng
Thanks !!!
Kai
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:U3**************@TK2MSFTNGXA02.phx.gbl...
Thanks for Christopher 's inputs.

Hi Kai,

As Christopher has mentioned, OnXXX (suppose XXX is event name), is a
method of a certain control which can be override by derived class while
XXX is the event defined in the control...

Genearlly, when a certain event is to be fired, the control will call its
OnXXX method, and the base class's implementation will call all the event
handlers registered for that event ...... So for OnXXX method, we can
override it if we're developing a certain control or a derived one from
existing control.... While as for event handler, it provide the means
for ther control's user (page developer ) to hook the event and inject
some custom code when the event got fired......

Hope this is what you're wondering...

If there're anything we didn't quite get or anything else we can help,
please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Christopher Reed" <ca****@nospam.nospam>
| References: <cN****************@newsread3.news.atl.earthlink.n et>
| Subject: Re: What is thre difference between OnClick and Click events?
| Date: Tue, 27 Dec 2005 23:21:03 -0600
| Lines: 52
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <ef*************@TK2MSFTNGP14.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip68-106-67-38.lu.dl.cox.net 68.106.67.38
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:367244
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| OnClick is the method while Click is the event. In essence, they are
the
| same. The difference is in the execution.
|
| If you set the OnClick attribute in your Button tag in the ASPX page,
then
| the event is automatically generated when the ASPX is compiled when the
| AutoEventWireup attribute in the Page directive is set to true. For
| example,
|
| <asp:Button id="btnOne" runat="server" Text="Click Me!"
| OnClick="btnOne_Click" />
|
| On the other hand, if you do not set the OnClick attribute, you can
always
| define the Click event as long as you set the AutoEventWireup attribute
in
| the Page directive to false. In your code-behind, you would most likely
do
| something like this (in C#):
|
| void Page_Init(Object objSender, EventArgs evtArgs)
| {
| ...
| btnOne.Click += new EventHandler(btnOne_Click);
| ...
| }
|
| For both, you have to create the method btnOne_Click:
|
| void btnOne_Click(Object objSender, EventArgs evtArgs)
| {
| ...
| }
|
| Hope this helps!
| --
| Christopher A. Reed
| "The oxen are slow, but the earth is patient."
|
| "kai" <ka******@earthlink.net> wrote in message
| news:cN****************@newsread3.news.atl.earthli nk.net...
| > Hi,
| > In ASP.NET , what is the difference between OnClick and Click events
for
| > a button? Because we have button click event, it can trigger events,
why
| > we still need OnClick?
| >
| > Please help.
| >
| > Thanks
| >
| > kai
| >
| >
| >
|
|
|

Dec 28 '05 #5

P: n/a
You're welcome Kai,

If there're anything else we can help, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "kai" <ka******@earthlink.net>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| References: <cN****************@newsread3.news.atl.earthlink.n et>
<ef*************@TK2MSFTNGP14.phx.gbl>
<U3**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: What is thre difference between OnClick and Click events?
| Lines: 120
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <u1****************@newsread3.news.atl.earthlink.n et>
| Date: Wed, 28 Dec 2005 18:43:38 GMT
| NNTP-Posting-Host: 66.32.80.38
| X-Complaints-To: ab***@earthlink.net
| X-Trace: newsread3.news.atl.earthlink.net 1135795418 66.32.80.38 (Wed, 28
Dec 2005 10:43:38 PST)
| NNTP-Posting-Date: Wed, 28 Dec 2005 10:43:38 PST
| Organization: EarthLink Inc. -- http://www.EarthLink.net
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!nntp.giganews. com!elnk-atl-nf1!newsfeed.
earthlink.net!stamper.news.atl.earthlink.net!newsr ead3.news.atl.earthlink.ne
t.POSTED!a96f5a29!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:367367
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi, Cheng
| Thanks !!!
| Kai
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:U3**************@TK2MSFTNGXA02.phx.gbl...
| > Thanks for Christopher 's inputs.
| >
| > Hi Kai,
| >
| > As Christopher has mentioned, OnXXX (suppose XXX is event name), is a
| > method of a certain control which can be override by derived class while
| > XXX is the event defined in the control...
| >
| > Genearlly, when a certain event is to be fired, the control will call
its
| > OnXXX method, and the base class's implementation will call all the
event
| > handlers registered for that event ...... So for OnXXX method, we can
| > override it if we're developing a certain control or a derived one from
| > existing control.... While as for event handler, it provide the
means
| > for ther control's user (page developer ) to hook the event and inject
| > some custom code when the event got fired......
| >
| > Hope this is what you're wondering...
| >
| > If there're anything we didn't quite get or anything else we can help,
| > please feel free to post here.
| >
| > Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| > --------------------
| > | From: "Christopher Reed" <ca****@nospam.nospam>
| > | References: <cN****************@newsread3.news.atl.earthlink.n et>
| > | Subject: Re: What is thre difference between OnClick and Click
events?
| > | Date: Tue, 27 Dec 2005 23:21:03 -0600
| > | Lines: 52
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Response
| > | Message-ID: <ef*************@TK2MSFTNGP14.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: ip68-106-67-38.lu.dl.cox.net 68.106.67.38
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:367244
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | OnClick is the method while Click is the event. In essence, they are
| > the
| > | same. The difference is in the execution.
| > |
| > | If you set the OnClick attribute in your Button tag in the ASPX page,
| > then
| > | the event is automatically generated when the ASPX is compiled when
the
| > | AutoEventWireup attribute in the Page directive is set to true. For
| > | example,
| > |
| > | <asp:Button id="btnOne" runat="server" Text="Click Me!"
| > | OnClick="btnOne_Click" />
| > |
| > | On the other hand, if you do not set the OnClick attribute, you can
| > always
| > | define the Click event as long as you set the AutoEventWireup
attribute
| > in
| > | the Page directive to false. In your code-behind, you would most
likely
| > do
| > | something like this (in C#):
| > |
| > | void Page_Init(Object objSender, EventArgs evtArgs)
| > | {
| > | ...
| > | btnOne.Click += new EventHandler(btnOne_Click);
| > | ...
| > | }
| > |
| > | For both, you have to create the method btnOne_Click:
| > |
| > | void btnOne_Click(Object objSender, EventArgs evtArgs)
| > | {
| > | ...
| > | }
| > |
| > | Hope this helps!
| > | --
| > | Christopher A. Reed
| > | "The oxen are slow, but the earth is patient."
| > |
| > | "kai" <ka******@earthlink.net> wrote in message
| > | news:cN****************@newsread3.news.atl.earthli nk.net...
| > | > Hi,
| > | > In ASP.NET , what is the difference between OnClick and Click
events
| > for
| > | > a button? Because we have button click event, it can trigger events,
| > why
| > | > we still need OnClick?
| > | >
| > | > Please help.
| > | >
| > | > Thanks
| > | >
| > | > kai
| > | >
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 29 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.