Which Button was submit the form in page load event

The sender argument to the handler contains a reference to the control which raised the event.

private void Button1_Click(object sender, EventArgs e)
{
    Button theButton = (Button)sender;
    ...
}

In the Load event: Use Request's Form collection will contain a key/value for the submitting button, but not for the others. So you can do something like

protected void Page_Load(object sender, EventArgs e)
{
    Button theButton = null;
    if (Request.Form.AllKeys.Contains("button1"))
        theButton = button1;
    else if (Request.Form.AllKeys.Contains("button2"))
        theButton = button2;
    ...
}

Comments

Popular posts from this blog

C# Crop white space from around the image

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

The specified version string contains wildcards, which are not compatible with determinism.