Hi Salam,
Does Shawn's suggestion address your problem? For dynamic created controls,
they need to be created in each page requests (no matter initiall request
or postback). Thereforce, you should take care that do not put the control
creation code into If Not IsPostBack Then ..... code block. Here is a
complete test page which contains code that creating a checkbox dynamically
and add it into Page's Form Control collection:
=====================
Partial Class Dynamic_DynamicControls
Inherits System.Web.UI.Page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
Dim chk As New CheckBox
chk.ID = "chkSelected"
chk.Text = "Selected"
chk.AutoPostBack = True
AddHandler chk.CheckedChanged, AddressOf chkSelected_CheckedChanged
Page.Form.Controls.Add(chk)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
End Sub
Protected Sub chkSelected_CheckedChanged(ByVal sender As Object, ByVal
e As System.EventArgs)
Response.Write("<br/>" & sender.Checked)
End Sub
End Class
=====================
In addition, here are some articles that dicussing on creating dynamic
controls on ASP.NET webform:
#HOW TO: Dynamically Create Controls in ASP.NET with Visual Basic .NET
http://support.microsoft.com/kb/317515/en-us
#How to: Add Controls to an ASP.NET Web Page Programmatically
http://msdn2.microsoft.com/en-us/library/kyt0fzt1.aspx
Hope this helps some. If you have any further questions on this, please
feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial
response from the community or a Microsoft Support Engineer within 1
business day is
acceptable. Please note that each follow up response may take approximately
2 business days
as the support professional working with you may need further investigation
to reach the
most efficient resolution. The offering is not appropriate for situations
that require
urgent, real-time or phone-based interactions or complex project analysis
and dump analysis
issues. Issues of this nature are best handled working with a dedicated
Microsoft Support
Engineer by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.