This is a migrated thread and some comments may be shown as answers.

AddHandler not firing in User Control

4 Answers 180 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
AMS
Top achievements
Rank 1
AMS asked on 15 Jan 2009, 08:55 AM
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.DataBind()  
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)  
    pnlProductAttributes.Controls.Add(rfv)  
End If 
pnlProductAttributes.Controls.Add(dropDownList) 

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()  
        GetInventory(skuId)  
    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

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jan 2009, 11:34 AM
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:
cs:
 
     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  
         Panel1.Controls.Add(ddl)  
         ddl.DataBind()  
          
     End Sub  
  
  
 
     Protected Sub ddl_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
         
     End Sub 
 
 

Thanks
Princy.
0
AMS
Top achievements
Rank 1
answered on 15 Jan 2009, 07:13 PM
Princy,

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
content.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,
Walter
0
Veselin Vasilev
Telerik team
answered on 19 Jan 2009, 03:54 PM
Hi AMS,

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

Thanks

Regards,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
AMS
Top achievements
Rank 1
answered on 24 Jan 2009, 12:08 AM
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.

Thanks,
Walter
Tags
ComboBox
Asked by
AMS
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
AMS
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or