ASP.net adding a label on page load

Posted on 2013-11-09
Medium Priority
Last Modified: 2013-11-10

I used the following code to try to add a label as my web page loads
but I can't see anything.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Sub Add_Controls()
            '1.Create an instance of the control and set its properties, as shown in the following example:
            Dim myLabel As New Label()
            myLabel.Text = "Sample Label"
            myLabel.ForeColor = Drawing.Color.AliceBlue

            '2.Add the new control to the Controls collection of a container already on the page, as shown in the following example:
            Dim Panel1 As New Panel()

            'Because the Controls property is a collection, you can use the AddAt method to place the new
            ' control at a specific location — for example, in front of other controls. However, this can introduce
            ' errors into the page. For details, see Dynamic Web Server Controls and View State.

        Catch ex As Exception

        End Try
    End Sub
Question by:Murray Brown
  • 2

Accepted Solution

QuinnDex earned 2000 total points
ID: 39635686
add this to the aspx page

<asp:Panel ID="Panel1" runat="server"></asp:Panel>

Open in new window

code behind

dim lbl as new Label()
lbl.Text = "This is me!"

Open in new window


Author Comment

by:Murray Brown
ID: 39636866

I did that and still can't see anything

Author Closing Comment

by:Murray Brown
ID: 39636924
Thanks. Tried it on a blank page and it worked

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…
Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question