2011-10-05 68 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

我正在讨论页面中的按钮 –

相关问题