Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Basic stuff

Reply
Thread Tools

Basic stuff

 
 
Sparko
Guest
Posts: n/a
 
      04-19-2005
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?
 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      04-19-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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?



 
Reply With Quote
 
 
 
 
Sparko
Guest
Posts: n/a
 
      04-19-2005
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
}
}
 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      04-20-2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Basic array stuff richard HTML 1 10-05-2008 10:04 PM
basic if stuff- testing ranges Donn Ingle Python 12 11-26-2007 09:18 PM
Basic Stuff wink.co.nr C++ 4 05-17-2007 07:46 PM
What is some basic stuff? Tom C++ 3 12-14-2003 12:46 AM
brief questions on basic stuff mat DVD Video 0 11-25-2003 10:36 PM



Advertisments