473,387 Members | 1,535 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,387 software developers and data experts.

Basic stuff

Hi, I am just starting to expore asp.net and I have coded a simple
HelloWorld type page using a csharp code-behind file. I have used
a <asp:Label /> server control and after wiring up my event handlers
I tried to set the Text property of the Label control in the Page_Load
method. When my page loads in the browser there is not text in the Label?
I'm sure I have declared the Label's object reference correctly. Can I
assign the label text in this way or does it have to be assigned in line?
Nov 19 '05 #1
3 872
Sparko:
Everything should be working, perhaps if you provided some code...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Sparko" <ma*********@shoosmiths.co.uk> wrote in message
news:16**************************@posting.google.c om...
Hi, I am just starting to expore asp.net and I have coded a simple
HelloWorld type page using a csharp code-behind file. I have used
a <asp:Label /> server control and after wiring up my event handlers
I tried to set the Text property of the Label control in the Page_Load
method. When my page loads in the browser there is not text in the Label?
I'm sure I have declared the Label's object reference correctly. Can I
assign the label text in this way or does it have to be assigned in line?

Nov 19 '05 #2
OK, here is the WebForm1.aspx.cs file, the aspx file is simple HTML
with the <asp:Label /> control as suggested ....

namespace dotNETDev
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for WebForm1.
/// </summary>
///
public class WebForm1 : System.Web.UI.Page
{
protected DropDownList cmb1;
protected Label Lbl1;
protected Button Btn1;
protected Table tbl1;
protected DropDownList combo1;
protected TableRow tblrw1;

public WebForm1()
{
Page.Init += new System.EventHandler(Page_Init);

}

private void Page_Load(object sender, System.EventArgs e)
{
Lbl1.Text = "HelloWorld";

}

public void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

private void Btn1_Click(object sender, EventArgs e)
{
Lbl1.Text = "Button Clicked1";

}

#region Web Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Btn1.Click += new System.EventHandler(this.Btn1_Click);
}
#endregion
}
}
Nov 19 '05 #3
Sparko wrote:
OK, here is the WebForm1.aspx.cs file, the aspx file is simple HTML
with the <asp:Label /> control as suggested ....

namespace dotNETDev
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for WebForm1.
/// </summary>
///
public class WebForm1 : System.Web.UI.Page
{
protected DropDownList cmb1;
protected Label Lbl1;
protected Button Btn1;
protected Table tbl1;
protected DropDownList combo1;
protected TableRow tblrw1;

public WebForm1()
{
Page.Init += new System.EventHandler(Page_Init);

}

private void Page_Load(object sender, System.EventArgs e)
{
Lbl1.Text = "HelloWorld";

}

public void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

private void Btn1_Click(object sender, EventArgs e)
{
Lbl1.Text = "Button Clicked1";

}

#region Web Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Btn1.Click += new System.EventHandler(this.Btn1_Click);
}
#endregion
}
}


One thing I notice is the handling of the Init event.
The code that is provided by VS.Net doesn't use a constructor
that attaches a handler to the Init event, but uses an override:

override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

remove the constructor and the Page_Init method and insert the above code.
The rest of the code looks OK.

Hans Kesting
Nov 19 '05 #4

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

Similar topics

9
by: Frantisek Fuka | last post by:
This thing keeps bugging me. It's probably some basic misunderstanding on my part but I am stumped. Let's say I have two Python files: file.py and file2.py. Their contents is as follows: ...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
8
by: Chris Asaipillai | last post by:
Hi there I have some questions for those experienced Visual Basic 6 programmers out there who have made the transition from VB6 to Vb.net. How long did it take you to learn at least the basic...
28
by: Randy Reimers | last post by:
(Hope I'm posting this correctly, otherwise - sorry!, don't know what else to do) I wrote a set of programs "many" years ago, running in a type of basic, called "Thoroughbred Basic", a type of...
14
by: MartinRinehart | last post by:
Working on parser for my language, I see that all classes (Token, Production, Statement, ...) have one thing in common. They all maintain start and stop positions in the source text. So it seems...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.