2

我正在尝试创建一个使用 AjaxControlToolkit 中的控件的 ASP.net 服务器控件。本质上,控件是一个下拉列表和一个按钮。当用户单击按钮时,将打开一个模式对话框 (modalPopupExtender)。该对话框有一个复选框列表,其中包含可供选择的选项列表。当用户选择他们的选项并点击 Ok 按钮时,在对话框中,对话框关闭并且所选选项应该被添加到下拉列表中。但是,发生的情况是,当用户做出选择并点击 OK 时,只会添加 Checkboxlist 中的最后一项。我认为这可能与我覆盖的继承函数有关。谁能告诉我我可能做错了什么?以下是相关代码:

<DefaultProperty("Text"), ToolboxData("<{0}:myServerControl runat=server> 
        </{0}:myServerControl >")> _
Public Class myServerControl 
Inherits CompositeControl
Implements INamingContainer, IPostBackEventHandler

Private myDropDownListAs New DropDownList
Private addPlant As New Button
Private _updatePanel As UpdatePanel
Private _modalExtenderOne As AjaxControlToolkit.ModalPopupExtender
Private lblWarning As Label
Private cb1 As New CheckBoxList
Private btnSavePlants As New Button
Private btnCancel As New Button

  Protected Overrides Function SaveViewState() As Object
    Return New Pair(MyBase.SaveViewState(), Nothing)
End Function


Protected Overrides Sub LoadViewState(ByVal savedState As Object)
    MyBase.LoadViewState(CType(savedState, Pair).First)
    EnsureChildControls()
End Sub

Protected Overrides Sub CreateChildControls()
    createDynamicControls()
    MyBase.CreateChildControls()
End Sub

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)       
    MyBase.OnInit(e)

End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    MyBase.OnLoad(e)
End Sub

 Private Sub createDynamicControls()
    Controls.Clear()
    AddHandler btnSavePlants.Click, AddressOf saveItems_Click
    _updatePanel = New UpdatePanel
    Dim myTable As New Table
    myTable = buildControl()  ' a funciton that returns a built table
    Dim myPanel As New Panel
    myPanel = buildDialog()  'a function taht returns a build modal dialog
    _updatePanel.ContentTemplateContainer.Controls.Add(myTable)
    _updatePanel.ContentTemplateContainer.Controls.Add(myPanel)
    Me.Controls.Add(_updatePanel)
End Sub

  Protected Sub saveItems_Click(ByVal sender As Object, ByVal e As EventArgs)
    Me.myDropDownList.Items.Clear()
    Try
        For Each i As ListItem In Me.cb1.Items
            If (i.Selected = True) Then
                Dim newLi As New ListItem
                With newLi
                    .Selected = False
                    .Text = i.Text
                    .Value = i.Value
                End With

                Me.myDropDownList.Items.Add(newLi)
            Else                    
            End If

        Next
    Catch ex As Exception

    End Try

End Sub

   Public Sub bindSelections(ByVal myList As List(Of myObject))

    For Each p As myObjectIn myList
        Dim newLI As New ListItem
        newLI.Value = p.EquipmentPK
        newLI.Text = p.EquipmentID

        Me.cb1.Items.Add(newLI)

    Next



End Sub


Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent

End Sub

End Class
4

0 回答 0