OnClick and onClick ?

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"?
LVL 2
born4codeAsked:
Who is Participating?
 
koolkraftConnect With a Mentor Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
FirePitsCommented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
FirePitsCommented:
There's really no difference besides where the action is process, server vs. client
0
 
nehayaConnect With a Mentor Commented:
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
 
born4codeAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.