• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

ASP.net adding a label on page load

Hi

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
        Add_Controls()
    End Sub

    Sub Add_Controls()
        Try
            'http://msdn.microsoft.com/en-us/library/kyt0fzt1(v=vs.110).aspx
            '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()
            Panel1.Controls.Add(myLabel)


            '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
0
Murray Brown
Asked:
Murray Brown
  • 2
1 Solution
 
QuinnDexCommented:
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!"
Panel1.Controls.Add(lbl) 

Open in new window

0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi

I did that and still can't see anything
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi
Thanks. Tried it on a blank page and it worked
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now