1
我有一個aspx頁面,其中包含幾個控件以及一個Button。當從JavaScript觸發回發時,哪個控件在apsx頁面中導致回發
<asp:Button ID="savebtn" runat="server" OnClick="savebtn_Click" Style="display: none" />
我使用此按鈕來觸發後期使用此按鈕的點擊事件。
//For post back
$(document).ready(function() {
var id = document.getElementById('<%= savebtn.ClientID %>');
//causes post back
id.Text = "postback";
id.click();
});
現在在頁面加載我想知道哪個控件導致回發。
我已經使用下面的代碼來找出哪個控件導致postpack,但它的返回null。可能是因爲我從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;
}
請幫
我正在使用一個叫做select2的JQuery插件。我使用這個插件來實現自動完成功能。在我從插件中選擇了一些值後,我想引起postpack,這樣我就可以在服務器端執行一些任務。 – SharpCoder