1

I read a tutorial about Asp.Net and copy some of the code in it it doesn't compile and I can't understand why. Here's my code:

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;
    }
}

On default.aspx.cs it doesn't recognize lblTime and Label1. Why does it happen?

Earlier, before I added LabelTime it runs just fine and I can't understand what's wrong with the code I added.

Edit: in Default.aspx.cs no control from Default.aspx recognized...

Thank you

Dror
  • 177
  • 3
  • 11

1 Answers1

0

It seems that the code was right but I used probably a wrong project, that's why it didn't compile...

Dror
  • 177
  • 3
  • 11