【发布时间】:2013-08-23 04:01:04
【问题描述】:
我有一个 aspx 页面,其中包含几个控件和一个按钮。
<asp:Button ID="savebtn" runat="server" OnClick="savebtn_Click" Style="display: none" />
我使用这个按钮通过这个按钮的点击事件触发post pack。
//For post back
$(document).ready(function () {
var id = document.getElementById('<%= savebtn.ClientID %>');
//causes post back
id.Text = "postback";
id.click();
});
现在在页面加载时,我想知道是哪个控件导致回帖。
我使用下面的代码来找出导致 postpack 的控件但它返回 null。可能是因为我从 JavaScript 触发了 post pack。
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;
}
请帮忙
【问题讨论】:
标签: javascript asp.net postback