.net – How to determine which button caused postback

asp.netnetpostbackvb.net

I have 2 button controls. When I click one i'm trying to determine which one caused a postback in the page load. How to do determine this?

Best Answer

What about using CommandName and CommandArgument has shown in this example. This way you can have just one handler.

<asp:Button id="Button1"
       Text="Sort Ascending"
       CommandName="Sort"
       CommandArgument="Ascending"
       OnCommand="CommandBtn_Click" 
       runat="server"/>

  <asp:Button id="Button2"
       Text="Sort Descending"
       CommandName="Sort"
       CommandArgument="Descending"
       OnCommand="CommandBtn_Click" 
       runat="server"/>