I have a aspx page which contains few controls along with a Button.
<asp:Button ID="savebtn" runat="server" OnClick="savebtn_Click" Style="display: none" />
I use this button to trigger post pack using the click event of this button.
//For post back
$(document).ready(function () {
var id = document.getElementById('<%= savebtn.ClientID %>');
//causes post back
id.Text = "postback";
id.click();
});
Now at the page load I want to know which control caused the post back.
I have used below code to find out which control caused the postpack but its returning null. May be because I am triggered the post pack from JavaScript.
private Control GetControlThatCausedPostBack(Page page)
{
//initialize a control and set it to null
Control ctrl = null;
//get the event target name and find the control
string ctrlName = Page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(ctrlName))
ctrl = page.FindControl(ctrlName);
//return the control to the calling method
return ctrl;
}
Please help