[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

ASP.net adding a label on page load

Posted on 2013-11-09
3
Medium Priority
?
410 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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 …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

656 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