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

ComboBox not firing events

5 Answers 150 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
StephenWRogers
Top achievements
Rank 1
StephenWRogers asked on 11 Jul 2008, 09:11 AM
I'm having a problem since upgrading from 2008.1.415 to 2008.1.619 with a ComboBox not firing the SelectedIndexChanged event.

I traced it back to the ClientID of the combobox having changed since the new version - where previously it was the full control hierarchy eg mainPlaceHolder$cplTopPaneContent$frmSalaryHistory$gradeSelector$dropDown it is now being rendered as just gradeSelector$dropDown.

Having spent a while debugging the new version, i think the problem lies with the new CreateHeader and CreateFooter methods:

        private void CreateFooter() 
        { 
            if (_footer == null
            { 
                this._footer = new RadComboBoxHeaderFooterControl(); 
                this.Controls.Add(Footer); 
                Footer.ID = this.ClientID + "_Footer"
                Footer.CssClass = RadComboBox.FooterCssClass; 
            } 
        } 
 
        private void CreateHeader() 
        { 
            if (_header == null
            { 
                this._header = new RadComboBoxHeaderFooterControl(); 
                this.Controls.Add(Header); 
                Header.ID = this.ClientID + "_Header"
                Header.CssClass = RadComboBox.HeaderCssClass; 
            } 
        } 

These methods make a reference to this.ClientID, and as they are being called while the control hierarchy is not yet finalised they can cause problems with caching of UniqueIDPrefixes for the controls.

This results in the controls being rendered with the wrong clientIDs and the events not firing.  This is discussed on pages such as http://dotnetslackers.com/DataGrid/re-49612_Accessing_ClientID_or_UniqueID_too_early_can_cause_issues.aspx

It's not easy to reproduce this in a small project, as I think the control has to be in a nested hierarchy before it starts breaking, but if you just want the header to have the same ClientID as the combobox, but with "_Header" suffixed to it, is it not possible to change the above code to

 
 
        private void CreateFooter() 
        { 
            if (_footer == null
            { 
                this._footer = new RadComboBoxHeaderFooterControl(); 
                this.Controls.Add(Footer); 
                Footer.ID = "_Footer"
                Footer.CssClass = RadComboBox.FooterCssClass; 
            } 
        } 
 
        private void CreateHeader() 
        { 
            if (_header == null
            { 
                this._header = new RadComboBoxHeaderFooterControl(); 
                this.Controls.Add(Header); 
                Header.ID = "_Header"
                Header.CssClass = RadComboBox.HeaderCssClass; 
            } 
        } 

and ASP.NET will take care of prefixing with the combobox's ID (as the header is a child control of the combobox)?

Thanks,

Stephen

5 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 14 Jul 2008, 12:39 PM
Hi Stephen,

We have implemented the change and it will be included in the official Q2 2008 release next week.

Also note that firing of the SelectedIndexChanged event is not related with the ID of the Header and Footer controls. Does the problem in your project persist when you remove the HeaderTemplate and FooterTemplate of the definition of your combobox? I suggest you test the project without the Header and Footer templates and let us known how this goes.



Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
StephenWRogers
Top achievements
Rank 1
answered on 14 Jul 2008, 01:16 PM
Hi,

The problem with the SelectedIndexChanged event is exactly to do with the code in CreateHeader and CreateFooter - that was the point of my email.

Try the following example:

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <div> 
 
        <asp:DataGrid ID="DataGrid1" runat="server"  AutoGenerateColumns="false" OnItemCreated="DataGrid1_ItemCreated" > 
     <Columns> 
        <asp:TemplateColumn> 
           <ItemTemplate> 
             <telerik:RadComboBox AutoPostBack="true" runat="server" ID="combo" OnSelectedIndexChanged="combo_SelectedIndexChanged"
             </telerik:RadComboBox> 
           </ItemTemplate> 
        </asp:TemplateColumn> 
     </Columns> 
     </asp:DataGrid> 
        </div> 
    </form> 
</body> 
</html> 
 


C#

using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Net; 
using System.Collections.Generic; 
using Telerik.Web.UI; 
 
public partial class _Default : System.Web.UI.Page  
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!Page.IsPostBack) 
        { 
            List<int> list = new List<int>(); 
            list.Add(1); 
            list.Add(2); 
            list.Add(3); 
 
            DataGrid1.DataSource = list; 
            DataGrid1.DataBind(); 
        } 
    } 
    protected void combo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        //put a breakpoint here; 
    } 
 
    protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e) 
    { 
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
        { 
            //Touching the clientID too early causes rendered ids to be wrong 
            // which also impacts on postback routing etc etc 
 
            RadComboBox combo = e.Item.FindControl("combo"as RadComboBox; 
            List<int> list = new List<int>(); 
            list.Add(1); 
            list.Add(2); 
            list.Add(3); 
            combo.DataSource = list; 
            combo.DataBind(); 
        } 
    } 

It's essentially just the example from the page I linked to, but with your ComboBox in the ItemTemplate.

Try that with version 1.619 and you'll see all the comboboxes are rendered with id="combo_Input", and hence the event doesn't fire and the inputs don't retain their values properly. 

Then change the two lines

Footer.ID = this.ClientID + "_Footer"
 
Header.ID = this.ClientID + "_Header"

to

Footer.ID = "Footer"
Header.ID = "Header"

and try again.  This time the ClientIDs aren't accessed before the control hierarchy has finalised, the ids are correctly set (eg "DataGrid1_ctl02_combo_Input"), and the events fire correctly.

It's quite a big problem with our site at the moment, CreateHeader and CreateFooter are fired whenever the combobox is created and if the control hierarchy is not finalised (as in the pretty simple example above), they stop working.

Thanks,

Stephen


0
Accepted
Rosi
Telerik team
answered on 15 Jul 2008, 10:01 AM
Hi ,

Please find the attached internal build where the change is implemented and let us known how this goes.

Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
StephenWRogers
Top achievements
Rank 1
answered on 15 Jul 2008, 03:08 PM
Hi,

Yeah this works OK.  I take it there the next release will be the Q2 2008 release, so the only way of getting a dev version of this version is by opening a support ticket?

I guess it would be good to know what other changes were made between 1.619 and 1.715 too, and if the Q2 release is not too far away?

Thanks,

Stephen
0
Rosi
Telerik team
answered on 16 Jul 2008, 06:58 AM
Hello ,

The Q2 2008 will be officially released next week. Then you will can read the release notes describing the changes between Q1 SP2 and Q2 builds.

Meanwhile you can open a support ticket and we will send you the dev version of the build which we send you in the previous message.


Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
StephenWRogers
Top achievements
Rank 1
Answers by
Rosi
Telerik team
StephenWRogers
Top achievements
Rank 1
Share this question
or