Click here to Skip to main content
15,882,552 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Can anyone explain about onClick and onClientClick, I also want to know the differences between them.

One more doubt is, Is onClick Clientside event or Server side event?
Posted
Updated 8-Jul-20 18:57pm

1.On Click Event sends the request to the server and in response performs the action.
2. On Client Click is very similar to onclick function which we use to write in Javascript... that is it executes the statements in the client side with out sending it to the server

Thanks
www.alacraft.com.au
 
Share this answer
 
OnClick will work on server side , OnClientClick will execute on client side before control passed to server.
If the client side code returns TRUE then it will go to server.
Generally programmers use onClientClick to validate the controls like textbox,etc.
The Button/LinkButton/ImageButton controls in asp.net 2.0 and more have a OnClientClick property. This is basically a shortcut for Attributes["onclick"] allowing you to do:

C#
Button1.OnClientClick = "alert('foo');";
 
Share this answer
 
v2
Comments
Sandeep Mewara 29-Jun-12 1:49am    
Good answer. 5!
Sounds like you have used a lot ;)
Vani Kulkarni 29-Jun-12 1:58am    
:) Thanks...Yes I have.
Sandeep Mewara 29-Jun-12 2:52am    
Learnt from ...Google?
OnClientClick is used to hadle the event at client side whereas OnClick is used to hadle event on server side.
 
Share this answer
 
<asp:Button ID="Btn_sub_app_user" runat="server" BackColor="#57B8C1" CssClass="btn" ForeColor="#37474F" Width="100px" Text="ثبت آپ‍‍‍‍‍‍‍‍" OnClientClick="GetSelectedApp();" OnClick="Btn_sub_app_user_Click" /><br />
its my button why didn't work!!!!
GetSelectedApp() is script
 
Share this answer
 
Comments
CHill60 18-Jun-17 16:22pm    
If you have a question of your own then use the red "Ask a question" link at the top of the page. Do not post questions or comments as solutions to old posts

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900