不识别某些标签

时间:2015-10-19 06:51:57

标签: asp.net

我阅读了一篇关于Asp.Net的教程并复制了一些它没有编译的代码,我无法理解为什么。 这是我的代码:

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MyFonts" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style>
        body
        {
            font-family: Verdana, Arial, Sans-Serif;
            font-size: small;
            color: yellowgreen;
        }
        .heading1
        {
            font-weight: bold;
            font-size: large;
            color: lime;
        }
        .heading2
        {
            font-weight: bold;
            font-size: medium;
            font-style: italic;
            color: #C0BA72;
        }
        .blockText
        {
            padding: 10px;
            background-color: #FFFFD9;
            border-style: solid;
            border-width: thin;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btSubmit" Text="Submit" runat="server" OnClick="Button_Click" />
        <div>
            <asp:Label ID="Label1" runat="server" />
        </div>
        <div>
            <asp:Label CssClass="heading1" ID="Label2" runat="server" Text="This Label Uses heading1"/>
            <br />
            This is sample unformatted text.<br /><br />
            <asp:Label CssClass="heading2" ID="Label3" runat="server" Text="This Label Uses heading2"/>
            <br />
            Here's more unformatted text.<br />
            <br />
            <div class="blockText" id="DIV1" runat="server">
                This control uses the blockText style. This control uses the blockText style. This
                control uses the blockText style. This control uses the blockText style.
            </div>
            <asp:Label ID="lblTime" runat="server" OnInit="lblTime_Init"/>
        </div>
    </div>
    </form>
</body>
</html>

Default.aspx.cs:


public partial class MyFonts : System.Web.UI.Page
{
    private void Page_Load(Object sender, EventArgs e)
    {
    }

    public void Button_Click(Object sender, EventArgs e)
    {
        Response.Write(((Button)sender).Text);
        Label1.Text = "You clicked <b>" + ((Button)sender).Text + "</b>";
    }

    protected void lblTime_Init(object sender, EventArgs e)
    {
        lblTime.Font.Name = "Verdana";
        lblTime.Font.Size = 20;
        lblTime.Font.Underline = true;
        lblTime.Font.Bold = true;
        lblTime.Font.Italic = true;
        lblTime.Font.Overline = true;
        lblTime.Font.Strikeout = true;
        lblTime.Text = DateTime.Now.ToString() + ". Font Name: " + lblTime.Font.Name;
    }
}

在default.aspx.cs上,它不识别lblTime和Label1。 为什么会这样?

早些时候,在我添加LabelTime之前它运行得很好,我无法理解我添加的代码有什么问题。

编辑:在Default.aspx.cs中,无法识别Default.aspx的控件......

谢谢

1 个答案:

答案 0 :(得分:0)

似乎代码是正确的,但我使用的可能是一个错误的项目,这就是为什么它没有编译......