动态复选框单击时出错 [英] Error on dynamic checkbox click

查看:97
本文介绍了动态复选框单击时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



这是我的方案:



1.我创建了一个动态表。

2.在该表中,我创建了动态面板

3.在面板中,有一个动态复选框。



我想为该复选框添加属性。

以下是我的代码:



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 & "'');")


           TempPanelrack.Controls.Add(BtnCab)
           TempPanelrack.Controls.Add(chkcab)

           Dim TC As New TableCell()
           TC.Controls.Add(TempPanelrack)
           TR.Cells.Add(TC)

           If CountCab Mod 4 = 0 Then
               Me.tableALL.Rows.Add(TR)
               TR = New TableRow()
           Else
               Me.tableALL.Rows.Add(TR)
           End If







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

      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)
      Else
          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

推荐答案

嗯,你的第一个问题是您似乎正在使用ASP.NET并且未正确标记您的问题。



其次:



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



我不是知道你做了什么,但它假设有一个名为chkcabchecked的javascript方法。我看到你有一个名为的VB.NET方法,它告诉我你没有得到你所做的最模糊的概念。你迫切需要阅读一些书籍并了解ASP.NET是什么。您的VB.NET代码在生成页面时运行,但浏览器不知道它存在。从浏览器调用代码的唯一方法是执行AJAX。你现在不应该担心AJAX。你显然是一个初学者,所以我认为没有人会将这个代码用于任何事情,没有任何级别让任何人支付你现在编写代码的道德。买一些书并通过它们学习,或许上课。
Well, your first issue is that you appear to be using ASP.NET and did not label your question properly.

Secondly:

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.


这篇关于动态复选框单击时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆