
84
|
Chapter 5: ASP.NET Server Controls
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Action Controls
Action controls allow users to perform some action on that page, such as navi-
gating to a different URL, submitting a form, resetting a form’s values, or
executing a client script. Table 5-2 lists the action controls.
The simplified syntax of these controls is as follows:
<asp:button id="MyButton" text="Click Me!!" runat="server"/>
<asp:imagebutton id="MyImageButton"
imageurl="aspnetian.jpg" runat="Server"/>
<asp:linkbutton id="MyLinkButton" text="Click Me" runat="server"/>
<asp:hyperlink id="MyHyperLink"
text="Click Me"
navigateurl="ActionControls.aspx"
target="_blank"
runat="server"/>
The controls can then be accessed programmatically with code fragments like the
following:
MyButton.CommandName = "Sort"
MyImageButton.CommandArgument = "Ascending"
MyLinkButton.CommandName = "Filter"
MyHyperLink.NavigateUrl = "http://dotnet.oreilly.com/"
In the preceding code snippet, the CommandName property is used on
postback to determine which action control was clicked by the
user, so as to determine which code should run. For example, you
can have multiple button controls on a page, each with its own
CommandName, but which all share a single Click event handler.
The event handler can then check the CommandEventArgs argu-
ment passed into the handler ...