Posted by : my solutions Wednesday, June 12, 2013

What is the difference between ONCLICK and ONCLIENTCLICK in Asp.net

Watch This Tutorial at youtube by using following Url :
http://www.youtube.com/watch?v=9tgRRNR933s 

About OnClick :

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Check Events" />

A Event will be create at server side as below

protected void Button1_Click(object sender, EventArgs e)
    {
         //write code here
          Response.Write("response coming from server");

    }

--------------------------------------
Execute the page

" click the button ofter you will  able to see the result ofter page refresh "

because asp:Button is server side control. 

But Now the same button will act like as  Native HTML button control.

How ?

About OnClientClick : 

Follow the following code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function m() {
            alert("hi");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Check Events" OnClientClick="m();" />
 
    </div>
    </form>
</body>
</html>

Now the button give alert box with "hi".

Note : Both Events will execute with clientclick as first and onclick as server


Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © complete .net tutorials - Skyblue - Powered by Blogger - Designed by Johanes Djogan -