23 August 2015

Identifying control causing postback in asp.net

If you are developing ASP.NET web application, sometimes you might be wondering how to identify which control was responsible for the page postback. In this post, I will try to explain how the ASP.NET page life cycle is going to identify which control caused the postback.

What are EVENTTARGET and EVENTARGUMENT fields in ASP.NET

When ASP.NET web page is rendered, have a look at the page source. In the HTML of the page, you will notice "EVENTTARGET" and "EVENTARGUMENT" hidden fields. Using this fields, ASP.NET is going to identify which control caused the post out of many HTML elements on the page.

How EVENTTARGET and EVENTARGUMENT fields helps to identify HTML element causing the postback?

When a page is rendered in the browser, launch the Developer Tools and inspect the HTML element which is doing the postback. When you inspect such HTML elements, you will see something like below.