Visual Studio .NET - how to set access key for form button and underline

Asked By Aldo Lin Lin on 09-Sep-08 12:31 AM

for (web)

how to set access key for form button

and how to set underline  for example    Add    (mean  Alt+A)


try this - Santhosh N replied to Aldo Lin Lin on 09-Sep-08 12:57 AM

Just modify the text property of the button to


It displays Add   and at the same time (Alt + A) works to invoke click event


Issue... - Atul Shinde replied to Aldo Lin Lin on 09-Sep-08 01:03 AM

1)   Set the text property of the button as &Add or &Exit.

2)   Then it will show text like this Add and Exit.

3)   While operating use Alt + A and Alt + E etc.

See this sample:To set an access key by using a Label control - Binny ch replied to Aldo Lin Lin on 09-Sep-08 01:35 AM

Add a Label control to the page to act as a caption for the control that you want to put focus on with an access key.

In a Label control, set the following properties:

      AccessKey:    Set this property to the letter or number to use with the ALT key, such as S to support ALT+S.
      AssociatedControlID:   Set this property to the ID of the control to set the focus on when the ALT-key sequence is pressed.
      Text   Optionally, use HTML to add an underline or other indicator to the Text property.

The following code example shows the markup for a Label control and a TextBox control. The Label control displays a caption for the TextBox control, with the letter L underlined to indicate that the access key for the text box is ALT+L.
<asp:Label ID="Label1" runat="server"
  Text="<u>L</u>ast name: ">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

reply - Binny ch replied to Aldo Lin Lin on 09-Sep-08 01:38 AM
in u can't have a shortcut access key !!! only in applications !!!
so if u were developing an application,
when u set the .Text = "Save" try this "&Save"
manually fixed or programmatically - Perry replied to Aldo Lin Lin on 09-Sep-08 02:25 AM


If you want to do it manually and it will not changed while program execution then you can set this value in Text field of button;s property window to "&Save" but if you want to do it programatically then you need to add the code mybutton.Text = "&Add" where you want to change the name.



keyboard shortcut in - sundar k replied to Aldo Lin Lin on 09-Sep-08 06:02 AM

Access keys are common way to enable keyboard shortcuts on your web page. In short, site visitor can press Alt + some key to get a button clicked or get focus to some textbox. Both ASP.NET 1.1 and ASP.NET 2.0 provide AccessKey property for buttons and text boxes. ASP.NET 2.0 has additional AssociatedControlID property, used in Label control to specify which control will be clicked or get focus.

Access Keys ASP.NET 1.1 example (also works in ASP.NET 2.0):

<asp:Label ID="WonderfulLabel" runat="server" 
  Text="My <u>W</u>onderful function [ALT + W]">
</asp:Label><br />
<asp:Button AccessKey="W" ID="btnWonderful" runat="server"></asp:Button>

Access Keys ASP.NET 2.0 example

<asp:Label ID="WonderfulLabel" runat="server"
  Text="My <u>W</u>onderful function [ALT + W]">
</asp:Label><br />
<asp:Button ID="btnWonderful" runat="server"></asp:Button>

So, in example above, button btnWonderful will be clicked when ALT + W is pressed.

You should avoid keys reserved by Web browser. Internet Explorer 6 uses F, E, V, T and H to open File, Edit, View, Tools and Help menu items. Firefox uses additional G and B to call its Go and Bookmark menus.

Above is sourced from,

hope this helps!