AddHandler not firing in User Control

5 posts, 0 answers
  1. AMS
    AMS avatar
    13 posts
    Member since:
    Jun 2006

    Posted 15 Jan 2009 Link to this post

    I am adding a radcombobox dynamically when certain parameters are met. This is happening inside an ajaxpanel in a user control. The code to add the combobox is as follows:
    Dim dropDownList As New RadComboBox  
    dropDownList.ID = associatedAttribute.Name  
    dropDownList.CssClass = "attributeDropdownList" 
    dropDownList.DataSource = associatedAttribute.AttributeItemCollection  
    dropDownList.DataTextField = "FormattedAmount" 
    dropDownList.DataValueField = "fldSkuSuffix" 
    dropDownList.Skin = "SkyBlue" 
    AddHandler dropDownList.SelectedIndexChanged, AddressOf dropDownList_SelectedIndexChanged  
    dropDownList.AutoPostBack = True 
    dropDownList.Items.Insert(0, New RadComboBoxItem("--Select--"String.Empty))  
    If associatedAttribute.IsRequired Then 
        Dim rfv As New RequiredFieldValidator()  
        rfv.ControlToValidate = dropDownList.ID  
        rfv.Display = ValidatorDisplay.None  
        rfv.ErrorMessage = String.Format("Please Select", associatedAttribute.Name)  
    End If 

    When the page is rendered, it is rendered correctly. So this all seems ok, except that the AddHandler is not firing. The code for the handler event is:
    Private Sub dropDownList_SelectedIndexChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
            Dim dropDownList As RadComboBox = TryCast(sender, RadComboBox)  
            If dropDownList IsNot Nothing Then 
                Dim myLabel As Label = TryCast(ThisPage.cartUpdatePanel.FindControl(dropDownList.ID), Label)  
                If myLabel IsNot Nothing Then 
                    myLabel.Text = String.Format("<strong>{0}:</strong>&nbsp;{1}<br/>", dropDownList.ID, dropDownList.SelectedItem.Text)  
                End If 
            End If 
            Dim skuId As String = GetSku()  
        End Sub 

    The code in the event handler works as i have tested this with just a regular asp dropdownlist. Why will it not work for radcombobox?

    Walter Burditt
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 Jan 2009 Link to this post

    Hello Walter,

    In which event are you trying to create and add a new combobox? I tried creating the combobox and adding its SelectionIndexChanged event handler in the PageLoad event and its working as expected. Check out for any differences from the code below:
         Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)  
             Dim ddl As New DropDownList()          
             ddl.DataSourceID = "SqlDataSource1"  
             ddl.DataTextField = "ContactName"  
             ddl.DataValueField = "ID"  
             AddHandler ddl.SelectedIndexChanged, AddressOf DropDownList1_SelectedIndexChanged  
             ddl.AutoPostBack = True  
         End Sub  
         Protected Sub ddl_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
         End Sub 

  3. AMS
    AMS avatar
    13 posts
    Member since:
    Jun 2006

    Posted 15 Jan 2009 Link to this post


    I am adding in the Page_Load event as well. This is in a user control not a regular aspx page.
    The way this is happening is like this:

    site.master page
    user control         <- Event handler is here and combobox is being created here.

    It is never firing off, but if I use the same code with a asp dropdownlist it works fine.

    Thanks for the help,
  4. Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 19 Jan 2009 Link to this post

    Hi AMS,

    I suggest that you open a new support ticket and attach a sample working project there demonstrating the issue.


    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. AMS
    AMS avatar
    13 posts
    Member since:
    Jun 2006

    Posted 23 Jan 2009 Link to this post

    I made a test project and it is working, so then I tried it again in my main project and it is working now. The only thing that has changed is it is now using the latest build of the controls. So something must have fixed it in the newer build.

Back to Top