简体   繁体   中英

ASP.NET Web Application not allowing Option for Controls in Default.aspx.cs file, why?

Using Microsoft Visual Web Developer 2008 here with a ASP.NET Web Application created by default.

I create a label control with ID="Label1" control in designer view within the Default.aspx file, than I go to Default.aspx.cs file and type in Label1.Visible = False; I immediately get Label1 underlined in red, and hovering over this code says that the Control does not exist in the Current Context.

So, how am I supposed to manipulate properties of a control?

Ok, so in the Default.aspx file, there is this:

<asp:Label ID="Label1" runat="server"></asp:Label>

In that same file very first line says this:

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

In Default.aspx.cs, I have this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IDSS
{
    public partial class _Default : System.Web.UI.Page
    {
        Label1.Visible = False;
    }
}

Label1.Visible is not defined in the current context? When I start typing the word Label, I see only "Label" in there, Label1 is not in there at all. If I selected Label and place a dot after it, I get only 2 options: Equals and ReferenceEquals

In Default.aspx.designer.cs there is this:

public partial class _Default {
    protected global::System.Web.UI.WebControls.Label Label1;
}

What is the problem here?

Define something like:

<asp:Label ID="Label1" runat="server" />

in you .aspx page . It should automatically create the realated definition in the .designer file. You do not need to manually create the definition in the designer file. If you do, then make sure it is a partial class...for your page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM