Sorry, my problem was there where a was thinking

line 154 [ l = CType(Page.FindControl("Label_" + sIDent), Label) ]

I have to us


If I adding controls into a TablePrincipal, I have to find is into it, not int Page

Sorry, was a lapsus..

Thank to Everybody!

----- l-Touched wrote: ----

Hello, I am writing my User Control code below this words for you facilities understand me, I am think that is very well commented


Fill rows's table with other tables (with 3 rows, one cell by row), each table has 3 controls: One Label, One TextBox and One Button
Each control is created with a different ID for example: Label_1, TextBox_1, Button_1 (for Table_1, and so go on).
Each "Click Event button" is managed by a Sub named "btnButton1_Click", like can have various buttons in the web page, this Sub identify each button by ID

At the begin of page (after the user control), there is a label named "lblSomeThing", and when some button is clicked the text in a label that is partner of the button will be appear in label named "lblSomeThing". In other words
If you click "Button_4", text in "label_4" will be appear in label named "lblSomeThing"


Whe you click some button, the respective text doesn't appear in in label named "lblSomeThing"

I think that my problem is in the Sub named "btnButton1_Click", line 154 [ l = CType(Page.FindControl("Label_" + sIDent), Label) ]

I think that the problem is when I am getting the control by ID, using "FindControl Method", maybe I haven't use Page object, and I have to use Parent object (because I am in programming in User control level)

Another problem is that the border=1 doesn't appear

Could someone explainme what have I change for get the wanted result

You only have to create a new User Control in your web project named "example1.ascx", and Copy a Paste the code
Thanks in advance

---Your code for the "example1.ascx" file is

<!--REMEMBER CHANGE the Inherits name project --><% Control Language="vb" AutoEventWireup="false" Codebehind="example1.ascx.vb" Inherits="Probe.example1" TargetSchema="" %><asp:label id="lblSomeThing" runat="server">--- lblSomeThing ---</asp:label><br><br><br><asp:table id="TablePrincipal" runat="server"></asp:table

---Your code for the "example1.ascx.vb" file is

Public Class example
Inherits System.Web.UI.UserContro

#Region " Variables for creating table

'Row and cell for principal tabl
Dim Row4Principal As TableRo
Dim Cell4Principal As TableCel

'Table which will in each row of de principal Tabl
Dim TableIntern As Tabl
Dim RowIntern As TableRo
Dim CellIntern As TableCel

'---Row 1/
Dim R1 As TableRo
Dim R1C1 As TableCel

'---Row 2/
Dim R2 As TableRo
Dim R2C1 As TableCel
Dim lblLabel1 As Labe

'---Row 3/
Dim R3 As TableRo
Dim R3C1 As TableCel
Dim txtTextBox1 As TextBo

'---Row 4/
Dim R4 As TableRo
Dim R4C1 As TableCel
Dim WithEvents btnButton1 As Butto

Protected WithEvents Label2 As System.Web.UI.WebControls.Labe
Protected WithEvents TablePrincipal As System.Web.UI.WebControls.Tabl
Protected WithEvents lblSomeThing As System.Web.UI.WebControls.Labe

#End Regio

#Region " Web Form Designer Generated Code

'This call is required by the Web Form Designer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(

End Su

'NOTE: The following placeholder declaration is required by the Web Form Designer
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim iBWidth As Integer = 1


'I have a problem with this following line,
'in the browser doesn't appear the border.

Dim NumID As Integer = 0

For NumID = 1 To 3
'---Row 1/3
R1 = New TableRow
R1C1 = New TableCell




'---Row 2/3
R2 = New TableRow
R2C1 = New TableCell

lblLabel1 = New Label
lblLabel1.Text = "label N° " + NumID.ToString
lblLabel1.ID = "Label_" + NumID.ToString



'---Row 3/3
R3 = New TableRow
R3C1 = New TableCell

txtTextBox1 = New TextBox
txtTextBox1.Text = "TextBox N° " + NumID.ToString
txtTextBox1.ID = "txtTextBox1_" + NumID.ToString


'---Row 4/4
R4 = New TableRow
R4C1 = New TableCell

R4C1.HorizontalAlign = HorizontalAlign.Center
btnButton1 = New Button
btnButton1.Text = "Button " + NumID.ToString
btnButton1.ID = "Button_" + NumID.ToString
AddHandler btnButton1.Click, AddressOf btnButton1_Click


'--- Adding rows to table---
TableIntern = New Table
TableIntern.ID = "table_" + NumID.ToString


'---Adding created table in my principal table (which is in HTML section)
Row4Principal = New TableRow
Cell4Principal = New TableCell

Cell4Principal.Controls.Add(TableIntern) 'Created table is in a cell

TablePrincipal.Rows.Add(Row4Principal) 'Here the table is in principal Table

End Sub

Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click

Dim sID As String = CType(sender, Button).ID 'I get the ID of button
Dim sIDent As String = Right(sID, sID.Length - InStr(1, sID, "_")) 'I get the number after "_", p.e. Button_12, I will get "12"

Dim l As Label
l = CType(Page.FindControl("Label_" + sIDent), Label) 'Getting the control by ID
If (Not l Is Nothing) Then
'This label is in the HTML section
lblSomeThing.Text = "label N° " + sIDent + "had write: '" + l.Text + "'"
End If

End Sub
End Class