Hi Raghavendra,
I did use a postpack. Here is the testcode that worked for me.
The aspx file :
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb"
Inherits="PlayInn.test"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp
anel id="Panel1" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</asp
anel>
<asp
anel id="Panel2" runat="server" Visible="False">
<asp:Button id="Button2" runat="server" Text="Button"></asp:Button>
</asp
anel>
</form>
</body>
</HTML>
The vb.file :
Public Class test
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Panel2 As System.Web.UI.WebControls.Panel
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
'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.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Protected Overrides Sub LoadViewState(ByVal savedState As Object)
MyBase.LoadViewState(savedState)
If ViewState("controlsadded") = True Then
AddControls()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim liNumber As Int32
Dim liCount As Int32
Dim loLabel As Label
Dim loControl As Control
liNumber = CType(TextBox1.Text, Int32)
Session("Number") = liNumber
If ViewState("controlsadded") Is Nothing Then
AddControls()
End If
For liCount = 1 To liNumber
loLabel = New Label
loLabel = CType(Panel2.FindControl("label" & liCount), Label)
loLabel.Text = "This label" & liCount
Next
Panel1.Visible = False
Panel2.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim liCount As Int32
Dim loLabel As Label
For liCount = 1 To CType(TextBox1.Text, Int32)
loLabel = New Label
Try
loLabel = CType(Panel2.FindControl("label" & liCount),
Label)
Response.Write("Label" & liCount & ".text = " &
loLabel.Text & "<br>")
Catch ex As Exception
Response.Write(ex.Message & "<br>")
End Try
Panel2.Visible = False
Next
End Sub
Private Sub AddControls()
Dim liNumber As Int32
Dim liCount As Int32
Dim loLabel As Label
liNumber = Session("Number")
For liCount = 1 To liNumber
loLabel = New Label
loLabel.ID = "label" & liCount
loLabel.EnableViewState = True
Panel2.Controls.AddAt(liCount - 1, loLabel)
Next
ViewState("controlsadded") = True
End Sub
End Class