?
Solved

OnClick and onClick ?

Posted on 2006-05-07
6
Medium Priority
?
3,182 Views
Last Modified: 2011-12-19
I put an "OnClick" attribute into my asp.net WebControl, to call a process:

<asp:button id="Button1" runat="server" Text="Button" OnClick="myButtonModule"></asp:button></td>

So, what is the difference between this "OnClick" and the javascript "onClick" ?
Is this something that is run "server side", or what?
Any "Browser Implications"?
0
Comment
Question by:born4code
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16626402
As by the documentation, it should be onClick:
http://www.htmlcodetutorial.com/linking/_A_onClick.html

I would hence stick to that, as I don't know which browsers would complain/ignore OnClick ...
0
 
LVL 1

Expert Comment

by:FirePits
ID: 16626434
onClick for an <asp:Button> calls a function that you define in your <script runat="server"> block. (server-side code) While onClick for a <input type="button"> call a Javascript function (client-side code)
0
 
LVL 1

Expert Comment

by:FirePits
ID: 16626442
There's really no difference besides where the action is process, server vs. client
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Accepted Solution

by:
koolkraft earned 1400 total points
ID: 16626452
the difference between the 2 are :

In the end there is none. But when you use an asp.net server control this server controls "becomes alive"  on the server and certain events are raised on the server in relation to your control

the rendering of the <asp:Button control results in a html tag that looks something like this <input type="button" onclick="__doPostBack('this','')" id="Button1" />

the OnClick event gets rendered as an onclick tag.

There are no browser implications. Asp.net renders everything browser compatible. When you use server controls you don't have to worry about browser compatibilty. The guys from MS did that for you.
0
 
LVL 6

Assisted Solution

by:nehaya
nehaya earned 600 total points
ID: 16626507
Both can be used like this:
<asp:button id="Button1" runat="server" Text="Button" OnClick="HandledInServer" OnClientClick="HnadeledInClientJavascript"></asp:button>

OnClick will be treated as a call to internal javascript function to call the server (post backing)..
but OnClientClick is to be used to do user javascript calls.. e.g. Delete button should be like this:
<asp:button id="btnDelete" runat="server" Text="Delete" OnClick="DoDelete" OnClientClick="return confirm('Are you sure you want to delete?');"></asp:button>
Here,
if u click on this button, first the OnClinetClick will be called.. and a confirmation box will pop up .. if you click yes, the calling of OnClick [which is calling javascript for function: '_doPostBack()' which will call the server to do delete operation.

Regards,
Nehaya
0
 
LVL 2

Author Comment

by:born4code
ID: 16630565
Thanks guys.  Your answers were only 20 minutes apart...

nehaya, the "OnClientClick" attribute was a bonus, so I gave you some points for assist.

Thanks again.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question