Access "dynamically created controls on page load" in page postback

Posted on 2011-05-04
Last Modified: 2012-05-11
hi experts,

I want to create table with name and checkbox for the values from database (I am trying to create it as dynamically...)
and then on submit button, the items for which checkbox is checked, want to calculate few fields from database.... and update database related to that checkbox.

I tried to do it as two ways
1. with client side controls in code behind, on page load. I am not able to retrieve the checkbox checked values on page postback.......
 'strDisplay.Text = strDisplay.Text & "<tr><td>" & reader2("name").ToString & " : </td><td><input type='checkbox' id='item" & reader("item").ToString & " ' name='' onclicked=saveItems(); style='font-family:Verdana; font-size:11px; width:50px;' /></td></tr>"

where strDisplay is label..........

2. created server side controls on page load, but it gets disappeared on page postback
                    Dim tc As New TableCell()
                    Dim tc2 As New TableCell()
                    Dim tr As New TableRow()
                    tc.Style.Add("font-size", "11px")
                    tc.Style.Add("font-family", "Verdana")
                    tc2.Style.Add("font-size", "11px")
                    tc2.Style.Add("font-family", "Verdana")

                    Dim _lbl As Label = New Label()
                    _lbl.ID = "lbl" & reader("item").ToString
                    _lbl.Text = reader2("name").ToString
                    Dim _checkbox As CheckBox = New CheckBox()
                    _checkbox.ID = "chk" & reader("item").ToString

Can you please help me to get dynamically created checkbox values on page postback.......

I am using VS 2010 and SQL Server 2008 and implementing all this using

Question by:dpd3891
    LVL 83

    Expert Comment


    Author Comment

    nothing seems work..........all are talking about how to create dynamic controls that I have already created......

    I want to get values of those controls after page postback...

    LVL 51

    Accepted Solution

    use method 1
    but instead of id, use name

    <input type='checkbox' id='item" & reader("item").ToString & " ' name='' onclicked=saveItems(); ... />


    <input type='checkbox' name='item" value="1" & reader("item").ToString & " ' name='' onclicked=saveItems(); ... />

    then use

    Request("item") and see what you get when it is checked (put a value too)

    Featured Post

    Course: HTML5 for Beginning Beginners

    Are you looking for an efficient introduction to HTML5? Have you tried other HTML5 courses and found them too complex? Do you need just the basics of HTML5 to use with Wordpress or other content management system? If you said yes to any of these questions, this course is for you.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now