虎克的博客

Enthusiasm Biogeography-Biodiversity Informatics-Data Sciences

ASP.NET的标准服务器控件-应用(一)

| Comments

1、标签控件Label Control

1.1 示例代码

<asp:Label id="labMsg" runat="server" text="hello"/>

 

labMsg.Text = "<p>This is the <i>First</i> line";

labMsg.Text += "<br>" + "This is second line</p>";

 

标签控件在HTML的返回形式是<span id="labMsg">hello</span>

1.1 Assigning an Access Key

例子如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LabelHotKeys.aspx.cs" Inherits="LabelHotKeys" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>
            Using AccessKey for Controls</h1>
        <asp:Label ID="labName" runat="server" AccessKey="N" AssociatedControlID="txtName"
            Text="&lt;u>N</u>ame">
        </asp:Label>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
        <asp:Label ID="labMonth" runat="server" AccessKey="M" AssociatedControlID="drpMonth"
            Text="&lt;u>M</u>onth">
        </asp:Label>
        <asp:DropDownList ID="drpMonth" runat="server">
            <asp:ListItem>January</asp:ListItem>
            <asp:ListItem>February</asp:ListItem>
            <asp:ListItem>March</asp:ListItem>
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>

代码说明:红色代码的含义是当在浏览器显示结果的时候使用ALT+N(AccessKey定义的)鼠标指针的焦点转移到文本框控件txtName(AssociatedControlID)上。但是不能定

   original link:
   <a href='http://Apiaceae.github.io/blog/2009/05/18/ASP.NET%E7%9A%84%E6%A0%87%E5%87%86%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%8E%A7%E4%BB%B6-%E5%BA%94%E7%94%A8%28%E4%B8%80%29/'>http://Apiaceae.github.io/blog/2009/05/18/ASP.NET%E7%9A%84%E6%A0%87%E5%87%86%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%8E%A7%E4%BB%B6-%E5%BA%94%E7%94%A8%28%E4%B8%80%29/</a><br/>
   &nbsp;written by <a href='http://Apiaceae.github.io'>Hooker</a>
   &nbsp;posted at <a href='http://Apiaceae.github.io'>http://Apiaceae.github.io</a>
   </p>

Comments