By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,432 Members | 795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,432 IT Pros & Developers. It's quick & easy.

How to add programmatically a label into a content page?

P: n/a
Hi,

How to add programmatically a label into a content page?
I tried this but doesn't work:

Thanks
Phil
content page:
------------
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

code-behind:
-----------
dim lb as label
lb = New Label
Content1.controls.add("lb")
Mar 8 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
xke
It won't work that way. Add another control inside
ContentPlaceHolder1, a table, a panel ...
Let's talk code:

YourPage.aspx:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
</asp:Content>

YourPage.aspx.cs or YourPage.aspx.vb

On Page_Load

C#
Label lbl = new Label();
lbl.Text = "This is me!";
Panel1.Controls.Add(lbl);

VB.NET
dim lbl as new Label()
lbl.Text = "This is me!"
Panel1.Controls.Add(lbl)
Let me know if it's not working.

On Mar 8, 5:31 pm, "Phil" <uuvt...@fff.tywrote:
Hi,

How to add programmatically a label into a content page?
I tried this but doesn't work:

Thanks
Phil

content page:
------------
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

code-behind:
-----------
dim lb as label
lb = New Label
Content1.controls.add("lb")

Mar 9 '07 #2

P: n/a
Hi xke, thanks for replying ...

i get an error: Name 'Panel1' is not declared

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim lbl As New Label()
lbl.Text = "This is me!"
Panel1.Controls.Add(lbl)
End Sub
End Class
aspx:
----
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="addlabelcontent.aspx.vb"
Inherits="addlabelcontent" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
</asp:Panel>
</asp:Content>



"xke" <xk****@gmail.comschreef in bericht
news:11**********************@v33g2000cwv.googlegr oups.com...
It won't work that way. Add another control inside
ContentPlaceHolder1, a table, a panel ...
Let's talk code:

YourPage.aspx:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
</asp:Content>

YourPage.aspx.cs or YourPage.aspx.vb

On Page_Load

C#
Label lbl = new Label();
lbl.Text = "This is me!";
Panel1.Controls.Add(lbl);

VB.NET
dim lbl as new Label()
lbl.Text = "This is me!"
Panel1.Controls.Add(lbl)
Let me know if it's not working.

On Mar 8, 5:31 pm, "Phil" <uuvt...@fff.tywrote:
>Hi,

How to add programmatically a label into a content page?
I tried this but doesn't work:

Thanks
Phil

content page:
------------
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

code-behind:
-----------
dim lb as label
lb = New Label
Content1.controls.add("lb")


Mar 9 '07 #3

P: n/a
Sorry, it works ... now !?!
"xke" <xk****@gmail.comschreef in bericht
news:11**********************@v33g2000cwv.googlegr oups.com...
It won't work that way. Add another control inside
ContentPlaceHolder1, a table, a panel ...
Let's talk code:

YourPage.aspx:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
</asp:Content>

YourPage.aspx.cs or YourPage.aspx.vb

On Page_Load

C#
Label lbl = new Label();
lbl.Text = "This is me!";
Panel1.Controls.Add(lbl);

VB.NET
dim lbl as new Label()
lbl.Text = "This is me!"
Panel1.Controls.Add(lbl)
Let me know if it's not working.

On Mar 8, 5:31 pm, "Phil" <uuvt...@fff.tywrote:
>Hi,

How to add programmatically a label into a content page?
I tried this but doesn't work:

Thanks
Phil

content page:
------------
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

code-behind:
-----------
dim lb as label
lb = New Label
Content1.controls.add("lb")


Mar 9 '07 #4

P: n/a
xke
glad to hear it!
On Mar 9, 5:27 am, "Phil" <s...@ff.dfgwrote:
Sorry, it works ... now !?!

"xke" <xke...@gmail.comschreef in berichtnews:11**********************@v33g2000cwv.g ooglegroups.com...
It won't work that way. Add another control inside
ContentPlaceHolder1, a table, a panel ...
Let's talk code:
YourPage.aspx:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
</asp:Content>
YourPage.aspx.cs or YourPage.aspx.vb
On Page_Load
C#
Label lbl = new Label();
lbl.Text = "This is me!";
Panel1.Controls.Add(lbl);
VB.NET
dim lbl as new Label()
lbl.Text = "This is me!"
Panel1.Controls.Add(lbl)
Let me know if it's not working.
On Mar 8, 5:31 pm, "Phil" <uuvt...@fff.tywrote:
Hi,
How to add programmatically a label into a content page?
I tried this but doesn't work:
Thanks
Phil
content page:
------------
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>
code-behind:
-----------
dim lb as label
lb = New Label
Content1.controls.add("lb")- Hide quoted text -

- Show quoted text -

Mar 9 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.