• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

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

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
                    tc.Controls.Add(_lbl)
                    Dim _checkbox As CheckBox = New CheckBox()
                    _checkbox.ID = "chk" & reader("item").ToString
                    tc2.Controls.Add(_checkbox)
                    tr.Cells.Add(tc)
                    tr.Cells.Add(tc2)
                    tbl.Rows.Add(tr)
                    Panel1.Controls.Add(tbl)


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 vb.net.

Thanks.
0
dpd3891
Asked:
dpd3891
1 Solution
 
dpd3891Author Commented:
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...

Thanks......
0
 
HainKurtSr. System AnalystCommented:
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)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now