Besides creating buttons that work as Submit buttons, you also can create command buttons, as discussed in the In Depth section of this chapter. You make a button into a command button by assigning text to its CommandName property, and you also can assign text to its CommandArgument property (following the lead of buttons in Java).
In the Buttons example, which you can see in Figure 15.6, I've set the bottom button's CommandName property to "Button2" and its CommandArgument property to "You clicked Button2". To recover those values, you add code to the Command event of this property, not the Click event. Here's what that event handler looks like:
Private Sub Button2_Command(ByVal sender As Object, ByVal e As _ System.Web.UI.WebControls.CommandEventArgs) Handles Button2.Command ⋮ End Sub
The CommandEventArgs object passed to us has both a CommandName and CommandArgument property, so I can display the command argument for this button in the text box in this example this way:
Private Sub Button2_Command(ByVal sender As Object, ByVal e As _ System.Web.UI.WebControls.CommandEventArgs) Handles Button2.Command TextBox2.Text = e.CommandArgument End Sub
You can see the result in Figure 15.7, where I've clicked the bottom button.