2011-10-05 67 views
1

我有一個問題。當我按下文本框中的「返回」鍵時,ASP.NET頁面必須執行一些AJAX操作。它執行Ajax操作,但它也重新加載或回發頁面。 現在我要問:如何知道哪個按鈕回傳頁面?

我怎麼能知道被點擊了哪個按鈕?

感謝您的關注!

回答

4

試試這個:

/// <summary> 
/// Retrieves the control that caused the postback. 
/// </summary> 
/// <param name="page"></param> 
/// <returns></returns> 
private Control GetControlThatCausedPostBack() 
{ 
    //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; 
} 
0

當一個按鈕有一個name屬性,獲取傳遞回來的表單數據。確保每個按鈕都有唯一的名稱。

+0

我敢肯定他是在談論鍵盤,而不是HTML表單按鈕上的按鈕。 – magnattic

+0

我正在討論頁面中的按鈕 –

相關問題