473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

What is thre difference between OnClick and Click events?

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
5 5828
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
3
by: Brett | last post by:
What is the following code doing? I see evt and event but what is the difference? <input type="radio" id="us_countryFlag1" name="us_country" onclick="togglePurDec(event)">Yes <script>...
2
by: Dan | last post by:
How do I catch both ondblclick and onclick on a div? /Dan *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
by: W. Wandrey | last post by:
Hallo, I'm a newbie and try to learn C# while trying to progr. a little game which in affect touches all aspects of the language: syntax, arrays, painting, events .... so on events I be stuck: ...
12
by: Nathan Sokalski | last post by:
What is the difference between the Page_Init and Page_Load events? When I was debugging my code, they both seemed to get triggered on every postback. I am assuming that there is some difference,...
3
by: Mikeon | last post by:
Hello! Today it came to me that ASP.NET has a special "feature" that takes an event name defined on a control and adds the "On" prefix for it when it is used in the ASPX file ie.: when you use...
7
by: amit | last post by:
Hello everybody, I need your advice on this. In my javascript I'm using two anchor <A> which both are to download a pdf file. That works fine but my question is why the "this" parameter in...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
2
by: DavidGeorge | last post by:
In an earlier thread I recounted a problem I was having, but it took a while to reduce the problem to it's basic components and the issue became somewhat confused in reaching that point. I hope you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.