Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 29th, 2007, 05:26 AM
Authorized User
 
Join Date: Sep 2004
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default asp:label

I'm having trouble populating the text property of a label from a codebehind file yet if I put the code into the actual webpage it works.

Eg, this works directly in the webpage:

<script language="vb" runat="server">
    Public Sub Page_Load()
     label1.text = "Hello"
    End Sub
</script>

But if I have the same code in a codebehind file like below, it doesn't work.


Public Class _Test

    Inherits System.Web.UI.Page

    Public Sub Page_Load()

        label1.text = "Hello"
        label1.visible = True

    End Sub
End Class
 
Old April 29th, 2007, 09:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

With in-line code, VWD sets the AutoEventWireup property to True. With this setting on, the ASP.NET runtime is able to find the Page_Load method for the Page's Load event.

However, with a Code Behind file, this setting is Off by default, so you need to explicitly say that the Page_Load method is the event handler for the Page's Load event, like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  label1.text = "Hello"
  label1.visible = True
End Sub

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old April 30th, 2007, 07:23 AM
Authorized User
 
Join Date: Sep 2004
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Imar

That worked perfectly. Thanks for your help. :)








Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in asp label vickytarun ASP.NET 1.0 and 1.1 Basics 2 November 3rd, 2007 06:17 AM
Change ASP.NET label color using Javascript shalan99 ASP.NET 2.0 Professional 4 May 22nd, 2007 02:09 AM
Problem with assignment the value for asp label GraceOriole ASP.NET 2.0 Professional 1 December 19th, 2006 06:59 AM
asp:Label control - 2 problems VictorVictor ASP.NET 2.0 Basics 8 April 14th, 2006 10:14 AM
Label Color in ASP.NET mistry_bhavin General .NET 1 January 17th, 2005 04:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.