Sponsored Ad

Saturday, July 10, 2010

How to call both server side and client side methods on button click

This simple method helps you to call server side C# method and client side javascript methods togather with one click. just assign these two parameters with name of C# and javascript functions.

OnClick

OnClientClick

 

How to call both server side and client side methods on button click

 

How to call both server side and client side methods on button click Example:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ">
<script runat="server">
    protected void btnClick_Click(object sender, EventArgs e)
{
Response.Write("Server side click.");
}
</script>
<script language="javascript">
function ClientClick()
{
alert('Client side click');
}
</script>

<html xmlns="">
<head>
    <title>call javascript and C# methods on single click.</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnClick"  runat="server" Text="Button" OnClientClick="ClientClick()" OnClick="btnClick_Click" />
        </div>
    </form>
</body>
</html>

2 comments:

  1. great man gud work i was luking for this post for whole day

    ReplyDelete
  2. gud wrk thanks i was luking for this post whole day

    ReplyDelete

Sponsored Ad

Development Updates