Finding which Control has caused PostBack in C#

Hi friends today iam going to post a Demo Code which demonstrates. which control have requested the post back

generally while using Ajax mostly we get postback with out getting into page life cycle

and some times we need to track which control caused the post back so in order to check that here is the sample code snippet

protected void Page_Load(object sender, EventArgs e)
    if (IsPostBack)
        string CtrlID = string.Empty;
        if (Request.Form[“__EVENTTARGET”] != null &&    Request.Form[“__EVENTTARGET”] != string.Empty)
            CtrlID = Request.Form[“__EVENTTARGET”];
            //Buttons and ImageButtons
            if (Request.Form[hidSourceID.UniqueID] != null && Request.Form[hidSourceID.UniqueID] != string.Empty)
                CtrlID = Request.Form[hidSourceID.UniqueID];



            “<script type=’text/javascript’>” +

            “window.onload=new function(){” +

            “alert(‘Control ID ” + CtrlID +

” caused postback.’);}” +


//the above sample was taken from post

About kakani santosh kumar

Working as Software Engineer in Prithvi Information Solutions having 3 years of Experience in Dotnet Framework ranging from 1.1 to 3.5
This entry was posted in Articles, Coding, Interview Questions, Programming, Uncategorized and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s