473,395 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

!!web control not recognised1 what comes first?

Hi, i am using code behind c# pages. I have put a couple of asp:labels on the
aspx html page. in the code behind i am trying to set them programatically
but am getting error

The type or namespace name 'mylabel' could not be found (are you missing a
using directive or an assembly reference?)

and it has a wiggly line under it. I have saved the aspx file, but cant get
the .cs file to recognise it. What comes first? Or what am I missing? I have
got
using System.Web.UI.WebControls;
at the top of my cs file.

using

Nov 18 '05 #1
7 1264
Your aspx:

<asp:Label id="lblTest" Runat="server"></asp:Label>

Your C#:

using System;
......
using System.Web.UI.WebControls;

namespace SomeSpace
{
public class MyPage : SomeNamespace.BaseClassName
{
protected Label lblTest;

private void Page_Load(...)
{
lblTest.Text = "Some Text";
}
}
}

Compile it and it'll work. Your C# "code-behind" class is the base class for
your aspx html page. Therefore, you have to declare your control in C# class
and since you're not going to use it in any other class make it "protected"
(not "private" or "public") so it'll be visible to your aspx page.

Regards,
Kikoz

"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:F8**********************************@microsof t.com...
Hi, i am using code behind c# pages. I have put a couple of asp:labels on
the
aspx html page. in the code behind i am trying to set them programatically
but am getting error

The type or namespace name 'mylabel' could not be found (are you missing a
using directive or an assembly reference?)

and it has a wiggly line under it. I have saved the aspx file, but cant
get
the .cs file to recognise it. What comes first? Or what am I missing? I
have
got
using System.Web.UI.WebControls;
at the top of my cs file.

using

Nov 18 '05 #2
you didn't give us quite enough code, but it ought to look something like:

<html>
<head></head>
<body>
<form runat="server" id="form1">
<asp:label id="date" runat="server" />
</form>
</body>
</html>

using System.Web.UI.WebControls;

public class WebForm1 : Page{

protected Label date; //are you missing this???

public void Page_Load(...){
date.Text = DateTime.Now.ToShortDateTime();
}
}
--
MY ASP.Net tutorials
http://www.openmymind.net/
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:F8**********************************@microsof t.com...
Hi, i am using code behind c# pages. I have put a couple of asp:labels on the aspx html page. in the code behind i am trying to set them programatically
but am getting error

The type or namespace name 'mylabel' could not be found (are you missing a
using directive or an assembly reference?)

and it has a wiggly line under it. I have saved the aspx file, but cant get the .cs file to recognise it. What comes first? Or what am I missing? I have got
using System.Web.UI.WebControls;
at the top of my cs file.

using

Nov 18 '05 #3
Are you using VS.NET or someting like Web Matrix, or Dreamweaver??
Note: if you are not using vs.net , then you have to manually compile this
codebehind file first, also referencing the system.web.dll.

"louise raisbeck" wrote:
Hi, i am using code behind c# pages. I have put a couple of asp:labels on the
aspx html page. in the code behind i am trying to set them programatically
but am getting error

The type or namespace name 'mylabel' could not be found (are you missing a
using directive or an assembly reference?)

and it has a wiggly line under it. I have saved the aspx file, but cant get
the .cs file to recognise it. What comes first? Or what am I missing? I have
got
using System.Web.UI.WebControls;
at the top of my cs file.

using

Nov 18 '05 #4
And you don't have to "manually" compile your code in vs.net?? :)
"Tampa .NET Koder" <Ta***********@discussions.microsoft.com> wrote in
message news:76**********************************@microsof t.com...
Are you using VS.NET or someting like Web Matrix, or Dreamweaver??
Note: if you are not using vs.net , then you have to manually compile this
codebehind file first, also referencing the system.web.dll.

"louise raisbeck" wrote:
Hi, i am using code behind c# pages. I have put a couple of asp:labels on
the
aspx html page. in the code behind i am trying to set them
programatically
but am getting error

The type or namespace name 'mylabel' could not be found (are you missing
a
using directive or an assembly reference?)

and it has a wiggly line under it. I have saved the aspx file, but cant
get
the .cs file to recognise it. What comes first? Or what am I missing? I
have
got
using System.Web.UI.WebControls;
at the top of my cs file.

using

Nov 18 '05 #5
yes guys it was the declaration of the web control
protected Label mylabel;

THANKS

(Tampa I am using vs.net)

do i have to do this for every control then or is there some way i can get
it to auto do this (think i know answer!)?

"Karl Seguin" wrote:
you didn't give us quite enough code, but it ought to look something like:

<html>
<head></head>
<body>
<form runat="server" id="form1">
<asp:label id="date" runat="server" />
</form>
</body>
</html>

using System.Web.UI.WebControls;

public class WebForm1 : Page{

protected Label date; //are you missing this???

public void Page_Load(...){
date.Text = DateTime.Now.ToShortDateTime();
}
}
--
MY ASP.Net tutorials
http://www.openmymind.net/
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:F8**********************************@microsof t.com...
Hi, i am using code behind c# pages. I have put a couple of asp:labels on

the
aspx html page. in the code behind i am trying to set them programatically
but am getting error

The type or namespace name 'mylabel' could not be found (are you missing a
using directive or an assembly reference?)

and it has a wiggly line under it. I have saved the aspx file, but cant

get
the .cs file to recognise it. What comes first? Or what am I missing? I

have
got
using System.Web.UI.WebControls;
at the top of my cs file.

using


Nov 18 '05 #6
If some of your functionality repeats on several pages (in several classes)
consider using UserControl. To fully automate it, create basic class
("MyBase", for example), base all classes/pages that use this UserControl on
that MyBase. Declare your control in MyBase the way we did with that lbl.
You'll have to insert control declaration in html on every page (there are
way to avoid it in 1.x version and there are Master Page thing in 2.0
version) and stop using designer. You can use a base class to "auto" declare
any web control the way described above.

Hope it helps.
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:BD**********************************@microsof t.com...
yes guys it was the declaration of the web control
protected Label mylabel;

THANKS

(Tampa I am using vs.net)

do i have to do this for every control then or is there some way i can get
it to auto do this (think i know answer!)?

"Karl Seguin" wrote:
you didn't give us quite enough code, but it ought to look something
like:

<html>
<head></head>
<body>
<form runat="server" id="form1">
<asp:label id="date" runat="server" />
</form>
</body>
</html>

using System.Web.UI.WebControls;

public class WebForm1 : Page{

protected Label date; //are you missing this???

public void Page_Load(...){
date.Text = DateTime.Now.ToShortDateTime();
}
}
--
MY ASP.Net tutorials
http://www.openmymind.net/
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:F8**********************************@microsof t.com...
> Hi, i am using code behind c# pages. I have put a couple of asp:labels
> on

the
> aspx html page. in the code behind i am trying to set them
> programatically
> but am getting error
>
> The type or namespace name 'mylabel' could not be found (are you
> missing a
> using directive or an assembly reference?)
>
> and it has a wiggly line under it. I have saved the aspx file, but cant

get
> the .cs file to recognise it. What comes first? Or what am I missing? I

have
> got
> using System.Web.UI.WebControls;
> at the top of my cs file.
>
> using
>


Nov 18 '05 #7
Ok something to think about. Thanks for all your help.

"Kikoz" wrote:
If some of your functionality repeats on several pages (in several classes)
consider using UserControl. To fully automate it, create basic class
("MyBase", for example), base all classes/pages that use this UserControl on
that MyBase. Declare your control in MyBase the way we did with that lbl.
You'll have to insert control declaration in html on every page (there are
way to avoid it in 1.x version and there are Master Page thing in 2.0
version) and stop using designer. You can use a base class to "auto" declare
any web control the way described above.

Hope it helps.
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:BD**********************************@microsof t.com...
yes guys it was the declaration of the web control
protected Label mylabel;

THANKS

(Tampa I am using vs.net)

do i have to do this for every control then or is there some way i can get
it to auto do this (think i know answer!)?

"Karl Seguin" wrote:
you didn't give us quite enough code, but it ought to look something
like:

<html>
<head></head>
<body>
<form runat="server" id="form1">
<asp:label id="date" runat="server" />
</form>
</body>
</html>

using System.Web.UI.WebControls;

public class WebForm1 : Page{

protected Label date; //are you missing this???

public void Page_Load(...){
date.Text = DateTime.Now.ToShortDateTime();
}
}
--
MY ASP.Net tutorials
http://www.openmymind.net/
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:F8**********************************@microsof t.com...
> Hi, i am using code behind c# pages. I have put a couple of asp:labels
> on
the
> aspx html page. in the code behind i am trying to set them
> programatically
> but am getting error
>
> The type or namespace name 'mylabel' could not be found (are you
> missing a
> using directive or an assembly reference?)
>
> and it has a wiggly line under it. I have saved the aspx file, but cant
get
> the .cs file to recognise it. What comes first? Or what am I missing? I
have
> got
> using System.Web.UI.WebControls;
> at the top of my cs file.
>
> using
>


Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Carolyn Vo | last post by:
I have been looking and looking but can't seem to find out how to get the row selected in a web control datagrid (NOT a web form datagrid!!!), and how to highlight the selected row. I'm sure this...
8
by: John Smith Jr. | last post by:
I am looking for some way to persist a table web control so when page_load event comes up, i can display the table as it was. I tried using ViewState with the rows collection but that didn't work...
7
by: Tuckers | last post by:
Hi, I am exploring c#. I want to reference a c# web control in a web page much like you can with an activeX control. The syntax for doing this in ActiveX is something like <OBJECT...
4
by: DotNetJunkies User | last post by:
I have created a User Control (a Pareto Chart) using C#. It works great in .Net Windows Apps, but I also need to use it in a Web Application (to view in IE). Everything I read on this seems to be...
6
by: Andre Ranieri | last post by:
I'm trying to create a login page for customers to log into our corporate website, our presidents naturally wants the user and password fields to populate from a cookie so the customer doesn't have...
3
by: dotnettester | last post by:
I have created a web control (.ascx). I placed the control on one of my asp.net page. In the control I have following properties.. public int itemId; private string itemName; public string...
5
by: John Kotuby | last post by:
Hi all, This is my first time trying to creaet and use a custome Web Control in a Web Site project in ASP.NET 2.0 with VS 2005 and VB. I created the control in a separate Web Control Library...
0
by: =?Utf-8?B?bWlrZQ==?= | last post by:
Hi, I am using ASP.NET 2.0. I have a gridview with only one column and it is a Template comuln. Column template contains several different controls some Web Controls some plain HTML controls....
5
by: David C | last post by:
Does anyone know how to email a web control filled with data to someone? I would like to email any web control (GridView, Calendar, etc.) to someone. Thanks. David
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.