There is no state between page requests - every page gets recreated from
scratch again.
Remove the Not IsPostBack check and you should be fine.
Attached is the code I was testing on my side
I used a panel to add the controls in the aspx
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Panel Runat="server" ID="pnlTest"></asp:Panel>
</form>
</body>
Code-behind :
Protected pnlTest As Panel
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim z As Integer
For z = 0 To 10
Dim ddl As System.Web.UI.WebControls.DropDownList = New
System.Web.UI.WebControls.DropDownList
ddl.Style("width") = "150"
ddl.ID = z.ToString
ddl.DataSource = GetData()
ddl.DataTextField = "cust_name"
ddl.DataValueField = "cust_id"
ddl.DataBind()
AddHandler ddl.SelectedIndexChanged, AddressOf ddl_SelectedIndexChanged
ddl.AutoPostBack = True
pnlTest.Controls.Add(ddl)
Next
End Sub
Public Sub ddl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs)
Dim x As String = "This function is never called!!!!!!!"
End Sub
Private Function GetData() As DataSet
'Some data --replace with your own
Dim ds As New DataSet
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("cust_name"))
dt.Columns.Add(New DataColumn("cust_id"))
Dim dtRow As DataRow = dt.NewRow
dtRow(0) = "1"
dtRow(1) = "1"
dt.Rows.Add(dtRow)
dtRow = dt.NewRow
dtRow(0) = "2"
dtRow(1) = "2"
dt.Rows.Add(dtRow)
ds.Tables.Add(dt)
Return ds
End Function
Hope this helps!
--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)
http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...
http://www.swanandmokashi.com/ http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
<j_****@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
It is having post back.
Also I have some code in the page load event, this code is executed
only if
If Not IsPostBack Then