2015-10-19 85 views
1

我讀了一篇關於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的控制公認...

謝謝

回答

0

看來,代碼是正確的,但我用了大概一個錯誤的項目,這就是爲什麼它沒有編譯...