开发者

How to know which button postbacks the page?

开发者 https://www.devze.com 2023-04-10 16:08 出处:网络
I have a probl开发者_JS百科em. When I press \"return\" key in the text box ASP.NETpage page must do some AJAX operation.It does Ajax operation but it also reloads or postbacks the page.

I have a probl开发者_JS百科em. When I press "return" key in the text box ASP.NETpage page must do some AJAX operation.It does Ajax operation but it also reloads or postbacks the page. And now I want to ask:

How can I know which button is clicked?

Thank your for your attention!!!


Try this:

   /// <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;
}


When a button has a name property, that gets passed back with the form data. Ensure each button has a unique name.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号