Using jQuery to Find which ASP.NET Control caused a PostBack

Here’s a simple script that uses jQuery to find out which ASP.NET Button caused a postback. You can similarly implement this script for other ASP.NET Controls too

<html xmlns="">
head runat="server">
title>Which Control Caused PostBack</title>
script src=""
<script type="text/javascript">
$(function () {
$("input:submit").click(function () {
+ " caused a postback");
form id="form1" runat="server">
asp:Button ID="Button1" runat="server" Text="Button1" />
asp:Button ID="Button2" runat="server" Text="Button2" />
asp:Button ID="Button3" runat="server" Text="Button3" />
asp:HiddenField ID="HiddenField1" runat="server" />


protected void Page_Load(object sender, EventArgs e)


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
As you can see, jQuery uses the Hidden field to store the value of the Button ID that caused a postback. The ID is printed using Response.Write()

Now click the Button2 and you get the following message


Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal


2 Responses to "Using jQuery to Find which ASP.NET Control caused a PostBack"
  1. slowery said...
    June 8, 2010 at 10:15 AM

    I have a concern about doing this - will the client side processing always complete before the server tries to read the hidden field in the postback? I have a case where I am saving a list of items to the hidden field and it dawned on me that there could be a timing issue?

  2. Roboblob said...
    June 9, 2010 at 6:19 AM

    Nice post.

    Here is how i solved this is ASP.NET:

    How to determine which Control caused PostBack on ASP.NET page


Copyright © 2009-2016 All Rights Reserved for by Suprotim Agarwal | Terms and Conditions