Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Really simple C# question-- setting the Text property of a label.


Message #1 by "Oliver, Wells" <WOliver@l...> on Thu, 5 Sep 2002 08:35:27 -0700
Trying to make a transition from VB.NET to C# and I'm unable to do this
really simple thing (which is of course probably not a good sign, but...).

Consider--

apsx:
<%@page language="C#" inherits="testPage" src="test.aspx.cs"%>
...
<asp:label id="testLabel" runat="server" />

aspx.cs:
using System;
using System.Web.UI.WebControls;

public class testPage : System.Web.UI.Page
{
	public Label testLabel;

	private void page_load (Object Sender, EventArgs E)
	{
		testLabel.Text = "Test";
	}
}

However, the "testLabel" is still blank.

Help? :)

Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com

Message #2 by =?iso-8859-1?Q?Gon=E7alo_Borr=EAga?= <goncalo.borrega@i...> on Thu, 5 Sep 2002 16:38:27 +0100
Write Page_Load instead of page_Load

Ucase<>LCase

Gon=E7alo Filipe Borr=EAga
goncalo.borrega@i...

InforTucano - Sistemas inform=E1ticos, Lda.
TagusPark - Ed. Inova=E7=E3o IV, Sala 722
2780-920 OEIRAS
Tel: ++ 351 21 4220140
Fax: ++ 351 21 4220149
ICQ#: 109844722



-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: quinta-feira, 5 de Setembro de 2002 16:35
To: ASP+
Subject: [aspx] Really simple C# question-- setting the Text property of 
a label.


Trying to make a transition from VB.NET to C# and I'm unable to do this 
really simple thing (which is of course probably not a good sign, 
but...).

Consider--

apsx:
<%@page language=3D"C#" inherits=3D"testPage" src=3D"test.aspx.cs"%> ... 
<asp:label id=3D"testLabel" runat=3D"server" />

aspx.cs:
using System;
using System.Web.UI.WebControls;

public class testPage : System.Web.UI.Page
{
	public Label testLabel;

	private void page_load (Object Sender, EventArgs E)
	{
		testLabel.Text =3D "Test";
	}
}

However, the "testLabel" is still blank.

Help? :)

Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com


---

ASP.NET 1.0 Namespace Reference with C# 
http://www.wrox.com/acon11.asp?ISBN=3D1861007442

ASP.NET 1.0 Namespace Reference with VB.NET 
http://www.wrox.com/acon11.asp?ISBN=3D1861007450

These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples. 

---
Message #3 by "Ray Jezek (TT)" <ray.jezek@t...> on Thu, 5 Sep 2002 10:39:12 -0500
Did you recompile after you added the "testLabel.Text = "Test";" code? 

 The syntax to looks good to me. 

 -----Original Message-----
From: 	Oliver, Wells [mailto:WOliver@l...] 
Sent:	Thursday, September 05, 2002 10:35 AM
To:	ASP+
Subject:	[aspx] Really simple C# question-- setting the Text property
of a label.

Trying to make a transition from VB.NET to C# and I'm unable to do this
really simple thing (which is of course probably not a good sign, but...).

Consider--

apsx:
<%@page language="C#" inherits="testPage" src="test.aspx.cs"%>
...
<asp:label id="testLabel" runat="server" />

aspx.cs:
using System;
using System.Web.UI.WebControls;

public class testPage : System.Web.UI.Page
{
	public Label testLabel;

	private void page_load (Object Sender, EventArgs E)
	{
		testLabel.Text = "Test";
	}
}

However, the "testLabel" is still blank.

Help? :)

Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com


---

ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442

ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450

These books are a complete reference to the ASP.NET namespaces 
for developers who are already familiar with using ASP.NET. 
There is no trivial introductory material or useless .NET 
hype and the presentation of the namespaces, in an easy-to use 
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes, 
giving you those real-world tips that the documentation doesn't 
offer, and demonstrating complex techniques with simple 
examples.  

---
Message #4 by "Bernd Waibel" <bwaibel@i...> on Thu, 5 Sep 2002 17:41:40 +0200

Hello Oliver,

you know that c# is case sensitive? In your case this means
that the page load event should read Page_Load. Also is
the Page_Load event registered during your OnInit event?
This is normally done by the designer, but if you did not
use the designer and wrote your code manually you also have
to register the event handler.



w> 	private void page_load (Object Sender, EventArgs E)
			^^^^^^^^^^^
w> 	{
w> 		testLabel.Text = "Test";
w> 	}
w> }
w> 
w> However, the "testLabel" is still blank.


HTH
bernd



-- 
Bernd Waibel
INWEMA AG
Dachauer Str. 15a
80335 Muenchen
Tel: +49 (0)89 89051660
Fax: +49 (0)89 89051699
mailto:bwaibel@i...
http://www.inwema.de






Bored? Want hours of entertainment?
Just set the initdefault to 6!


Message #5 by "Oliver, Wells" <WOliver@l...> on Thu, 5 Sep 2002 09:03:53 -0700
Thanks for the advice.

I rewrote it as "Page_Load" (have to keep the case sensitivity in mind; I
think it's definitely a good trait of a programming language). However, it
seems to work without the OnInit handler being written.

Why would this be? Does it have anything to do with the AutoEventWireUp
directive? I do not have that set to true or false in my page, and I think
it's false by default.

Thanks.

-----Original Message-----
From: Bernd Waibel [mailto:bwaibel@i...] 
Sent: Thursday, September 05, 2002 8:42 AM
To: ASP+
Subject: [aspx] RE: Really simple C# question-- setting the Text property of
a label.




Hello Oliver,

you know that c# is case sensitive? In your case this means that the page
load event should read Page_Load. Also is the Page_Load event registered
during your OnInit event? This is normally done by the designer, but if you
did not use the designer and wrote your code manually you also have to
register the event handler.



w> 	private void page_load (Object Sender, EventArgs E)
			^^^^^^^^^^^
w> 	{
w> 		testLabel.Text = "Test";
w> 	}
w> }
w> 
w> However, the "testLabel" is still blank.


HTH
bernd



-- 
Bernd Waibel
INWEMA AG
Dachauer Str. 15a
80335 Muenchen
Tel: +49 (0)89 89051660
Fax: +49 (0)89 89051699
mailto:bwaibel@i...
http://www.inwema.de






Bored? Want hours of entertainment?
Just set the initdefault to 6!



---

ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442

ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450

These books are a complete reference to the ASP.NET namespaces 
for developers who are already familiar with using ASP.NET. 
There is no trivial introductory material or useless .NET 
hype and the presentation of the namespaces, in an easy-to use 
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes, 
giving you those real-world tips that the documentation doesn't 
offer, and demonstrating complex techniques with simple 
examples.  

---

Message #6 by "Bernd Waibel" <bwaibel@i...> on Thu, 5 Sep 2002 18:16:44 +0200

w> language). However, it
w> seems to work without the OnInit handler being written.
w> 
w> Why would this be? Does it have anything to do with the 
w> AutoEventWireUp
w> directive? I do not have that set to true or false in my 
w> page, and I think
w> it's false by default.

hmmm, that's strange. Normally this should not work. Did you
have a look at the designer generated code region in your
code behind file? The event registration takes place there.

Actually i do not know the meaning of the AutoEventWireUp
directive. I know that there is this directive, but i
never changed the default value. Take a look in the
help for this.

bernd



-- 
Bernd Waibel
INWEMA AG
Dachauer Str. 15a
80335 Muenchen
Tel: +49 (0)89 89051660
Fax: +49 (0)89 89051699
mailto:bwaibel@i...
http://www.inwema.de






Bored? Want hours of entertainment?
Just set the initdefault to 6!


Message #7 by "Oliver, Wells" <WOliver@l...> on Thu, 5 Sep 2002 09:18:51 -0700
Yeah, I am not using VS.NET so there is no generated code (just a straight
text editor). I have no OnInit handler, either.

Curious, eh. Hey, if it works, it works, right? :)

-----Original Message-----
From: Bernd Waibel [mailto:bwaibel@i...] 
Sent: Thursday, September 05, 2002 9:17 AM
To: ASP+
Subject: [aspx] RE: Really simple C# question-- setting the Text property of
a label.




w> language). However, it
w> seems to work without the OnInit handler being written.
w> 
w> Why would this be? Does it have anything to do with the
w> AutoEventWireUp
w> directive? I do not have that set to true or false in my 
w> page, and I think
w> it's false by default.

hmmm, that's strange. Normally this should not work. Did you have a look at
the designer generated code region in your code behind file? The event
registration takes place there.

Actually i do not know the meaning of the AutoEventWireUp directive. I know
that there is this directive, but i never changed the default value. Take a
look in the help for this.

bernd



-- 
Bernd Waibel
INWEMA AG
Dachauer Str. 15a
80335 Muenchen
Tel: +49 (0)89 89051660
Fax: +49 (0)89 89051699
mailto:bwaibel@i...
http://www.inwema.de

Message #8 by =?iso-8859-1?Q?Gon=E7alo_Borr=EAga?= <goncalo.borrega@i...> on Thu, 5 Sep 2002 17:32:54 +0100
There is no need for the OnInit EventHandler if u don't have
code-behind... Page_Load is default

Gon=E7alo Borr=EAga

-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: quinta-feira, 5 de Setembro de 2002 17:19
To: ASP+
Subject: [aspx] RE: Really simple C# question-- setting the Text prope 
rty of a label.


Yeah, I am not using VS.NET so there is no generated code (just a 
straight text editor). I have no OnInit handler, either.

Curious, eh. Hey, if it works, it works, right? :)

-----Original Message-----
From: Bernd Waibel [mailto:bwaibel@i...]
Sent: Thursday, September 05, 2002 9:17 AM
To: ASP+
Subject: [aspx] RE: Really simple C# question-- setting the Text 
property of a label.




w> language). However, it
w> seems to work without the OnInit handler being written.
w>
w> Why would this be? Does it have anything to do with the
w> AutoEventWireUp directive? I do not have that set to true or false in 

w> my page, and I think
w> it's false by default.

hmmm, that's strange. Normally this should not work. Did you have a look 
at the designer generated code region in your code behind file? The 
event registration takes place there.

Actually i do not know the meaning of the AutoEventWireUp directive. I 
know that there is this directive, but i never changed the default 
value. Take a look in the help for this.

bernd



--
Bernd Waibel
INWEMA AG
Dachauer Str. 15a
80335 Muenchen
Tel: +49 (0)89 89051660
Fax: +49 (0)89 89051699
mailto:bwaibel@i...
http://www.inwema.de


---

ASP.NET 1.0 Namespace Reference with C# 
http://www.wrox.com/acon11.asp?ISBN=3D1861007442

ASP.NET 1.0 Namespace Reference with VB.NET 
http://www.wrox.com/acon11.asp?ISBN=3D1861007450

These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples. 

---

  Return to Index