asp.net c# examples code for web developers.

How to use AccessKey in asp.net

AccessKey in asp.net
AccessKey property is very helpful in asp.net. When someone presses the AccessKey the specific control is focus. In this example I create a web form name AccessKeyExample.aspx. When someone presses the Alt+N key the TextBox1 is focused and when he press Alt+C the TextBox2 is focused. Here is the source code of AccessKeyExample.aspx file.
AccessKeyExample.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to use AccessKey in asp.net</title>
</head>
<body style="padding:25px">
    <form id="form1" runat="server">
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">      
            AccessKey in ASP.NET
        </h2>      
        <hr width="450" align="left" color="Gainsboro" />
        <asp:Label
            ID="Label1"
            runat="server"
            Text="Your <u>N</u>ame"
            AssociatedControlID="TextBox1"
            AccessKey="N"
            Font-Bold="true"
            ForeColor="ForestGreen"
            >
        </asp:Label>
        <asp:TextBox 
            ID="TextBox1" 
            runat="server"
            >
        </asp:TextBox>
        <br /><br />
        <asp:Label 
            ID="Label2" 
            runat="server" 
            Text="<u>C</u>ity Name" 
            AssociatedControlID="TextBox2"
            AccessKey="C"
            Font-Bold="true"
            ForeColor="ForestGreen"
            />
        <asp:TextBox 
            ID="TextBox2" 
            runat="server"
            >
        </asp:TextBox>
    </div>
    </form>
</body>
</html>
More asp.net examples
Copyright © 2008-2015 | asp.net c# examples | asp-net-example.blogspot.com | Author Saiful Alam