get submit button id

后端 未结 7 728
抹茶落季
抹茶落季 2021-01-21 02:57

Inside asp.net form I have few dynamically generated buttons, all of this buttons submit a form, is there a way to get which button was submit the form in page load event?

7条回答
  •  悲&欢浪女
    2021-01-21 03:54

    protected void Page_Load(object sender, EventArgs e) {            
        string id = "";
        foreach (string key in Request.Params.AllKeys) {
            if (!String.IsNullOrEmpty(Request.Params[key]) && Request.Params[key].Equals("Click"))
                id = key;
        }
        if (!String.IsNullOrEmpty(id)) {
            Control myControl = FindControl(id);
            // Some code with myControl
        }
    }
    

提交回复
热议问题