Click here to Skip to main content
13,555,747 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all

Here is my scenario:

1. I create a dynamic table.
2. Inside that table, I create dynamic panel
3. Inside the panel, there is a dynamic checkbox.

I want to add attributes for that checkbox.
Below is my code:

For Each drCab As DataRow In dt.Rows
           Dim TempPanelrack As New Panel
           Dim BtnCab As New Button
           Dim chkcab As New CheckBox
           TempPanelrack.HorizontalAlign = HorizontalAlign.Center
           TempPanelrack.BorderStyle = BorderStyle.Inset
           TempPanelrack.Width = 110
           TempPanelrack.Height = 80
           TempPanelrack.ID = drCab("REFNO_T")

           BtnCab.Text = drCab("REFNO_T") & vbCrLf & "(" & CStr(drCab("NAME_T")).Substring(0, 12) & ")" & vbCrLf & "-" & CDate(drCab("FRDATETIME_D")).ToString("HH:mm") & "-"
           BtnCab.BorderStyle = BorderStyle.Groove
           BtnCab.ToolTip = drCab("NAME_T") & vbCrLf & "From: " & CDate(drCab("FRDATETIME_D")).ToString("dd/MM/yyyy HH:mm:ss") & vbCrLf & " To: " & CDate(drCab("TODATETIME_D")).ToString("dd/MM/yyyy HH:mm:ss") & " "
           BtnCab.Attributes.Add("onclick", "Showdetails('" & drCab("REGISNO_T") & "');")

           BtnCab.Width = 110
           BtnCab.Height = 80
           BtnCab.Font.Size = 8
           BtnCab.Font.Bold = True

           chkcab.ToolTip = drCab.Item("REFNO_T")
           chkcab.BorderStyle = BorderStyle.None
           chkcab.ID = drCab.Item("REFNO_T")

           chkcab.Attributes.Add("onClick", "chkcabchecked('" & TempPanelrack.ID & "');")


           Dim TC As New TableCell()

           If CountCab Mod 4 = 0 Then
               TR = New TableRow()
           End If

Private Sub chkcabchecked(ByVal panelid As String)
      'Dim chkbox As CheckBox = CType(sender, CheckBox)

      Dim mainContent As ContentPlaceHolder = DirectCast(Me.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
      'Dim chkcontrol As Panel = DirectCast(mainContent.FindControl("Panel1"), Panel)
      Dim tr As Table = DirectCast(mainContent.FindControl("tableALL"), Table)
      Dim trpanels As Panel = DirectCast(tr.FindControl(panelid), Panel)
      Dim chkbox As CheckBox = DirectCast(trpanels.FindControl("chkcab"), CheckBox)
      If (Not chkbox Is Nothing) Then
          ' Get control's parent.
          'Dim chkcontrol2 As Control = chkcontrol.Parent
          MsgBox("Parent of the text box is : " & chkbox.ID)
          MsgBox("Control not found.....")
      End If

  End Sub

However, the error
that I get when I click on the checkbox is:
Microsoft JScript runtime error: 'chkcabchecked' is undefined
Posted 8-Jan-13 21:40pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Well, your first issue is that you appear to be using ASP.NET and did not label your question properly.


chkcab.Attributes.Add("onClick", "chkcabchecked('" & TempPanelrack.ID & "');")

I don't know what you thnk this does, but it assumes there's a javascript method called chkcabchecked. I see you have a VB.NET method called that, which tells me you have not got the foggiest notion of what you're doing. You desperately need to read some books and understand what ASP.NET is. Your VB.NET code runs when a page is being generated, but the browser has no idea it exists. The only way to call your code behind from the browser is to do AJAX. You should not worry about AJAX for now. You're clearly a beginner, so I assume no-one is going to use this code for anything, there is no level on which it would be moral for anyone to pay you to write code right now. Buy some books and work through them, take a class perhaps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180515.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100