?
Solved

ASP.net adding a label on page load

Posted on 2013-11-09
3
Medium Priority
?
406 Views
Last Modified: 2013-11-10
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
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
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!"
Panel1.Controls.Add(lbl) 

Open in new window

0
 

Author Comment

by:Murray Brown
ID: 39636866
Hi

I did that and still can't see anything
0
 

Author Closing Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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