Maybe I'm the one not doing anything right but i'm trying to cause a page to display a given information as soon as it load.
I'm using labels display the said information. The problem here is, in the Page_Load method, i can't seem to call any of the labels or textboxes that i intend to use to display the info.

I tried it again by creating a method called info_Load in an experimental web-app. when i called the label, it worked and the site displayed the info but when i tried this method on my actuall web-app i got the same error. It said the Label is non-existent in this context.

can someone please help me sort this out?

Recommended Answers

All 3 Replies

Make sure the label you are trying to access in code behind Page_Load() method is actually there on the aspx page. Check its ID attribute . You can access that particular label via its id and assign its text property to whatever you want it to be.

Label1.Text="This is My Info";

use this code in default.aspx.cs
In page load()
{
label.text="hello";
}

or you want to use text color in label text

use namespace ;

using system.drawing;

or rewrite above code like this

In page load()
{
label.text="hello";
label.color=forecolor.red;
}

from
Mind Bird Solutions
<snipped>

Thanks guys, I found the solution to the problem. Quite a rediculus one too. Apparently, I forgot to mention that i had added the forms from a previous project so the inheritance attribute was still directed to that project. Once i changed it in the .aspx everything was fine. Lemme give a sample that way if anybody encounters that problem they'll know what to do.

This is the first code.

<%@ Page Language="C#"  AutoEventWireup="true" CodeBehind="HomePage.aspx.cs" Inherits="MainProject.HomePage" %>

And this is the corrected code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HomePage.aspx.cs" Inherits="MainProj.HomePage" %>

Thanks guys, and a happy new year to you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.