Jump to content
  • Advertisement
Sign in to follow this  
Alpha_ProgDes

[.net] Dropdownlist event not firing

This topic is 3691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Really all I'm trying to do is get my dropdown to allow me to dynamically load my usercontrols. But the SelectedIndexChanged event/method isn't firing. I have no idea why. Please help!
Imports System.Web
Imports System.Web.SessionState


Partial Class _Default
    Inherits System.Web.UI.Page

    Dim userControlListOfIDs As New Dictionary(Of String, String)
    Dim listOfControls As New List(Of UserControl)


    Public Sub New()

        Dim oneButton As UserControl = LoadControl("~/OneButtonUserControl.ascx")
        Dim oneLabel As UserControl = LoadControl("~/OneLabelUserControl.ascx")
        Dim oneTextBox As UserControl = LoadControl("~/OneTextBoxUserControl.ascx")
        Dim twoButton As UserControl = LoadControl("~/TwoButtonUserControl.ascx")
        Dim twoLabel As UserControl = LoadControl("~/TwoLabelUserControl.ascx")
        Dim twoTextBox As UserControl = LoadControl("~/TwoTextBoxUserControl.ascx")

        listOfControls.Add(oneButton)
        listOfControls.Add(oneLabel)
        listOfControls.Add(oneTextBox)
        listOfControls.Add(twoButton)
        listOfControls.Add(twoLabel)
        listOfControls.Add(twoTextBox)


        Dim i As Integer = 1
        Dim ucLabel As String = "UserControl"

        For Each uControl As UserControl In listOfControls
            ucLabel = ucLabel & i.ToString()
            userControlListOfIDs.Add(ucLabel, uControl.UniqueID)
            i = i + 1
        Next
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        If Page.IsPostBack Then
            'UCDropDownList.SelectedIndex = Int32.Parse(HiddenField1.Value)
        End If

        If Not Page.IsPostBack Then

            UCDropDownList.DataSource = userControlListOfIDs
            UCDropDownList.DataTextField = "key"
            UCDropDownList.DataValueField = "value"
            UCDropDownList.DataBind()
        End If
    End Sub

    Protected Sub UCDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles UCDropDownList.SelectedIndexChanged
        HiddenField1.Value = UCDropDownList.SelectedIndex.ToString()
        Dim aUserControl As UserControl

        For Each childControl As UserControl In listOfControls
            If childControl.UniqueID = UCDropDownList.SelectedValue Then
                aUserControl = childControl
                Exit For
            End If
        Next

        'This code doesn't work, though it should....
        '
        'For Each randomType As System.Type In listOfControlTypes
        '    If TypeOf aUserControl Is randomType Then
        '        aUserControl = CType(aUserControl, randomType)
        '    End If
        'Next

        
        UCPlaceHolder.Controls.Add(aUserControl)
    End Sub
End Class

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!