asp.net.ph

Skip Navigation Links

Adding Button Controls to a Web Forms Page

Controls You Can Use on Web Forms   ASP.NET Standard Controls   Button Controls


Adding buttons to a page is a simple process.

To add a Button Web server control to a Web Forms page

  1. Declare an <asp:Button> or <asp:LinkButton> element on the page.
  2. Set the caption by setting the control’s Text property.
  3. 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" />
Button1.aspx
Run Sample | View Source

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.

To define a button access key

  • 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.

See Also

Setting Web Server Control Properties Programmatically   Responding to Button Control Events



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note