problem with oncheckedchanged when dynamically created checkboxes

Posted on 2006-11-16
Last Modified: 2012-05-05
Hi,i have an editor.aspx where i have a table named sbaTable. That table is dynamically filled with rows in my code page editor.aspx.vb...On every row I have one checkbox and one textbox.. what i want to do is to disable textbox whenever checkbox on same row is checked=true!

editor.aspx.vb i have a loop that counts as many rows as i need(works fine)..
Private Sub PopulateGrid()
...create tablerow
...create tablecell "tcOk"
Dim chkOK as new checkbox = "ok-" + tdindex.text
chkOK.autopostback = true
''chkOK.oncheckedchanged" doesnot exist here for some reason(OnCheckedChanged exists in designer mode)!? that is why i tried with handlern below...
addhandler chkOK.checkedchanged, adressof chk_OncheckedChanged --

...create tablecell "tcNote"
Dim txtNote as new textbox = "note-" + tdindex.text
...addrows and cells to the table mm..
End Sub

Public sub chk_OncheckedChanged(ByVal sender As Object,ByVal e As EventArgs)

Dim checkBox as checkbox = Ctype(sender, CheckBox)
Dim idString as string =
End Sub

Problem = chk_OnCheckedChanged is never hit...can i do this the way i am trying oris there another solution??

Thanks in advance
Question by:adismesevic
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 10

Expert Comment

ID: 17963144
I think the handler is correct.  However, make sure the table is not re-generated on postback. You may try to generate the table in Page_PreRender to ensure that the viewstate preserves the controls that you add.


Author Comment

ID: 17963917
Hi Thanks for your answer.. i tried to create
 Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
         'If Not Page.IsPostBack Then
         'End If
End Sub

it doesnot help table is regenereted anyway and i can't use 'If Not Page.IsPostBack Then either because then i dont get anything back when page the same time i must set autopostback = true for my checkbox or nothing will happen when clicked!!

Author Comment

ID: 17971245
anyone know anything about this??..i have searched the google but cant find any solution there either!?
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

LVL 10

Expert Comment

ID: 17975613
hmmm....did u try to enable viewstate?

Author Comment

ID: 17977631
yes, i tried that too now..still not there an easier way to do this with javascript?
LVL 10

Expert Comment

ID: 17980237
hmm....I'll try a sample today and keep you posted on how it works - give me until the evening
LVL 10

Expert Comment

ID: 17983217
ok - got it - it was PreInit not PreRender as I initially said. See a quick and dirty implementation - hopefully u get the idea.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">
    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
    End Sub
    Protected Sub PopulateGrid()
        Dim tb As New Table
        Dim tr As New TableRow
        Dim tc As TableCell = Nothing
        tc = New TableCell
        Dim chkok As New CheckBox
        chkok.AutoPostBack = True
        AddHandler chkok.CheckedChanged, AddressOf chk_oncheckchanged
    End Sub
    Protected Sub chk_oncheckchanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim chkok As CheckBox = CType(sender, CheckBox)
        Response.Write("Checked: " & chkok.Checked.ToString())
    End Sub


<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">

Author Comment

ID: 18009468
Hi, first of all thank you very much for your answers I leaned some stuff that i didnot know, but unfortunately it didnt help me...when i tried your last suggestion i got some other stuff that i couldnot avoid mm
Anyway i solved it with is solution if anyone else woould need it....

chkOk.Attributes.Add("onclick", "chkChecked(document.forms[0].note_" + tdIndex.Text + ")")

 <script type="text/javascript" language="JavaScript">
   // functions to disable/enable dynamically created checkboxes/textboxes in tblSba
                function chkChecked(obj)
                     obj.disabled = !(obj.disabled);
                function txtChanged(chkobj, noteobj)
                        if (noteobj.value == '') {
                         chkobj.disabled = false;
                         else if (noteobj.value != ''){
                         chkobj.disabled = true;                        
LVL 10

Expert Comment

ID: 18014578
awesome.. glad u got it working!


Accepted Solution

DarthMod earned 0 total points
ID: 18076596
PAQd, 250 points refunded.

CS Moderator

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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