Controls You Can Use on Web Forms ASP.NET Standard Controls Button Controls
Adding buttons to a page is a simple process.
- Declare an <
asp:Button
> or <asp:LinkButton> element on the page.
- Set the caption by setting the control’s Text property.
- Assign the handler that will receive control when the onClick event of the button occurs ( i.e., when a user clicks the control ).
<asp:button text="Click Me" onClick="doSomething" runat="server" />
Because buttons execute commands, it can be useful to specify an access key for a button. Users can then press ALT plus the access key to choose the button. Note, though, that access keys are not supported in all browsers.
- Set the accessKey property to a single character. For example, to make the access key ALT plus the character "B", specify "B" as the value of the accessKey property.
<asp:button text="Click Me" accessKey="c" onClick="doSomething" runat="server" />
NOTE: In Windows applications, access keys are typically indicated on a button using an underlined character. This facility is not available for Button Controls due to restrictions in HTML. If you want to be able to display the access key for a button, you can use the HtmlInputButton or HtmlButton control.
Adding an ImageButton control is slightly more involved that working with other button types. See Creating Graphical Button Controls.
Setting Web Server Control Properties Programmatically Responding to Button Control Events