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

Equivilent to Attributes.Add("onchange", script) for RadCombo

2 Answers 193 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 04 May 2009, 05:17 PM
I am converting some traditional combo boxes to RadCombo boxes on a page. Each of the combo boxes is in a user control that is dynamically added to the page at runtime.

In the code behind, I am building some client side javascript that will call a custom ajax web service to do some calculations and such.

For example:

        StringBuilder javaScript = new StringBuilder(); 
        javaScript.Append("saveLuminaireInvestment("); 
        javaScript.Append("$get('" + this.lblLuminaireID.ClientID + "').innerHTML, "); 
        javaScript.Append("$find('" + this.cmbExistFixture.ClientID + "').value, "); 
        javaScript.Append("$find('" + this.cmbTCPFixture.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtQuantity.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtTCPQuantity.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtTCPCostPerFixture.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtTCPInstallCost.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtTCPRebate.ClientID + "').value"); 
        javaScript.Append("); "); 
 
        cmbExistFixture.Attributes.Add("onChange", javaScript.ToString()); 
 

But now I need to change this to use the RadCombo boxes.

How do I change this:

cmbExistFixture.Attributes.Add("onChange", javaScript.ToString());

to the equivilent in the RadCombo? Since the javascript that is being executed is dynamically generated, and each one is unique, I can't set this in the markup with OnClientSelectedIndexChanged.

Can I set "OnClientSelectedIndexChanged to some javascript (like above) rather than a named function?

Greg






2 Answers, 1 is accepted

Sort by
0
Helen
Telerik team
answered on 05 May 2009, 11:01 AM
Hi Greg,

You may find helpful the following forum posts:

http://www.telerik.com/community/forums/aspnet-ajax/combobox/onchange-and-ie.aspx
http://www.telerik.com/community/forums/aspnet-ajax/combobox/onchange-event-for-input-element.aspx


Regards,
Helen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Greg
Top achievements
Rank 1
answered on 05 May 2009, 04:10 PM
Those links helped me solve the issue. Here is what I ended up with:

        StringBuilder javaScript = new StringBuilder(); 
        javaScript.Append("saveLuminaireInvestment("); 
        javaScript.Append("$get('" + this.lblLuminaireID.ClientID + "').innerHTML, "); 
        javaScript.Append("$find('" + this.RadComboBoxExistingLuminaire.ClientID + "').get_value(), "); 
        javaScript.Append("$find('" + this.RadComboBoxTCPLuminaire.ClientID + "').get_value(), "); 
        javaScript.Append("$get('" + this.txtQuantity.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtTCPQuantity.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtTCPCostPerFixture.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtTCPInstallCost.ClientID + "').value, "); 
        javaScript.Append("$get('" + this.txtTCPRebate.ClientID + "').value"); 
        javaScript.Append("); "); 
 
        StringBuilder javaScript2 = new StringBuilder(); 
        javaScript2.Append("LinearCalcWS.getTCPFixtureEquiv($find('" + RadComboBoxExistingLuminaire.ClientID + "').get_value(), function(result) { if (result != null) { "); 
        javaScript2.Append("$find('" + this.RadComboBoxTCPLuminaire.ClientID + "').findItemByValue(result.TCPFixtureID).select(); "); 
        javaScript2.Append("$get('" + this.lblExistFixtureDesc.ClientID + "').innerHTML = result.ExistingFixtureDescription; "); 
        javaScript2.Append("$get('" + this.lblTCPFixtureDesc.ClientID + "').innerHTML = result.TCPFixtureDescription; "); 
        javaScript2.Append(javaScript.ToString()); 
        javaScript2.Append("} });"); 
 
        StringBuilder javaScript3 = new StringBuilder(); 
        javaScript3.Append("LinearCalcWS.getTCPFixtureDescription($find('" + RadComboBoxTCPLuminaire.ClientID + "').get_value(), function(result) { if (result != null) { "); 
        javaScript3.Append("$get('" + this.lblTCPFixtureDesc.ClientID + "').innerHTML = result; "); 
        javaScript3.Append(javaScript.ToString()); 
        javaScript3.Append("} });"); 
 
        RadComboBoxExistingLuminaire.OnClientSelectedIndexChanged = "function() {" + javaScript2.ToString() + "}"
        RadComboBoxTCPLuminaire.OnClientSelectedIndexChanged = "function() {" + javaScript3.ToString() + "}"
 

However, now I have a new problem that only shows up in FireFox.

In IE7, when I select a value from the first ComboBox (RadComboBoxExistingLuminaire), it properly updates the value of the second ComboBox (RadComboBoxTCPLuminaire) and also updates a couple of labels in the User Control. The second combo box is set based on the value of the first. Sort of a recommended replacement function.

It also properly saves the data via the AJAX call to the database. No problem.

However, in FireFox, when I select a value in the first combo box, it properly updates the second combobox and the labels, BUT, once I click off of the first combo box (to move to a text box, for example) or tab to the next control, the first combo resets itself to some random index (and then also causes the second combo box to set itself to a different value).

It's not always reproducable as to which index it will get set to.

To give you the bigger picture of where the RadComboBoxes are, the page has an AjaxControlToolkit TabPanelContainer control on it (this was developed before we started using Telerik controls) and within the container, is the TabPanel that this is on. In that TabPanel is a repeater, and the elements of the repeater are a user control and the user control contains the combo boxes.

It appears to be working fine in IE7 (and Safari), but not in FireFox.
Tags
ComboBox
Asked by
Greg
Top achievements
Rank 1
Answers by
Helen
Telerik team
Greg
Top achievements
Rank 1
Share this question
or