<controlname_event>不是'ASP.default_aspx </controlname_event>的成员

时间:2012-01-03 03:22:07

标签: asp.net

我在Visual Web Developer 2010 Express中使用以下ASP.NET 2.0代码,每次关于我的控件时都会出现以下错误。

我想知道我是否可以在ASP.NET 4.0中使用特定的ASP.NET 2.0代码以及我做错了什么?

    ERRORS:
    Error   1   'lblTime_Init' is not a member of 'ASP.default_aspx'.   

    Error   2   'chkUnderLine_CheckedChanged' is not a member of 'ASP.default_aspx'.        

    Error   3   'chkStrikeout_CheckedChanged' is not a member of 'ASP.default_aspx'.    

    Error   4   'chkOverLine_CheckedChanged' is not a member of 'ASP.default_aspx'.

Default.aspx的

<%--<@ Page Language="C#" AutoEventWireup="true" 

CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Checkbox Control</title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 267px">

    <h1>Checkbox Control</h1>
    <asp:Label ID="lblTime" runat="server" 
    OnInit="lblTime_Init" 
            style="position: relative" />
    <br />
    <br />

        <asp:CheckBox ID="chkUnderLine" runat="server"
            AutoPostBack="True"
            Text="Underline?"
            TextAlign="Left"
            oncheckedChanged="chkUnderLine_CheckedChanged" 
            style="position: relative"  />

        <asp:CheckBox ID="chkStrikeout" runat="server" 
         AutoPostBack="True"
            Text="Strikeout?"
         oncheckedChanged="chkStrikeout_CheckedChanged" 
            style="top: 49px; left: 9px; position: relative; width: 82px; float: left"/>

        <asp:CheckBox ID="chkOverLine" runat="server" 
            AutoPostBack="True"
            Text="Overline?"
            oncheckedChanged="chkOverLine_CheckedChanged" 
            style="float: left; position: relative; top: 16px; left: -72px" />

    </div>
    </form>
</body>
</html>
  --%>

“default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

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

    protected void chkUnderLine_CheckedChanged(object sender, EventArgs e)
    {

        if (chkUnderLine.Checked)
            lblTime.Font.Underline = true;
        else
            lblTime.Font.Underline = False;
    }

    protected void chkOverLine_CheckedChanged(object sender, EventArgs e)
    {
        if (chkOverLine.Checked)
            lblTime.Font.OverLine = true;
        else
            lblTime.Font.Overline = false;
    }
    protected void chkStrikeout_CheckedChanged(object sender, EventArgs e)
    {
        if (chkStrikeout.Checkout)
            lblTime.Font.Strikeout = true;
        else
            lblTime.Font.Strikeout = false;
    }
}

0 个答案:

没有答案