Tuesday, December 7, 2021

Difference between ONclientClick and onClick event in Asp.net button

onClientClick works on client side and onclick works on server side.

<asp:Button Text="Get TextBox Details" runat="server" OnClientClick="return GetTextBoxDetails()" />

    <script type="text/javascript">
        function GetTextBoxDetails() {
            var id = GetClientID("txtName");
            var txtName = document.getElementById(id);
            alert("Client ID: " + id + "\nValue: " + txtName.value);
            return false;
        }
or


<a href="www.mysite.com" onclick="return theFunction();">Item</a>

<script type="text/javascript">
    function theFunction () {
        // return true or false, depending on whether you want to allow the `href` property to follow through or not
    }
</script>

reference:-  https://www.c-sharpcorner.com/blogs/difference-between-onclick-and-onclientclick1

No comments:

Post a Comment