Solved

ASP.net adding a label on page load

Posted on 2013-11-09
3
373 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:murbro
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
QuinnDex earned 500 total points
Comment Utility
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:murbro
Comment Utility
Hi

I did that and still can't see anything
0
 

Author Closing Comment

by:murbro
Comment Utility
Hi
Thanks. Tried it on a blank page and it worked
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now