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

RadCombo in Custom Ajax Control

4 Answers 96 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Keith Thorne
Top achievements
Rank 1
Keith Thorne asked on 30 Mar 2010, 11:50 PM
I am trying to create a custom Ajax control consisting of one radcombo and about 6 text box controls. I want to populate the text boxes with details of the selected item in the rad combo. I have this working with a basic html drop down, the change event on the drop down fires off which access a web service w/ json serialization and it's very simple to update the text boxes. I've declared my control like so:

public class GlnComboPartyPicker : DataBoundControl, IPostBackDataHandler, IScriptControl, INamingContainer//, IPostBackDataHandler//, IDataSource

I later implement the GetScriptDescriptors method:
  IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors() {
      EnsureChildControls();
      ScriptControlDescriptor descriptor = new ScriptControlDescriptor("MyControlNS.MyControl", this.ClientID);

The control renders, the radcompo is populated and scrolls nicely etc.. BUT, normally I would add a handler to a basic html dropdown in the javascript that initializes the client class:
MyControlNS.MyControl.prototype = {
    initialize: function() {
        GLNPartyPickerControl.PartyPicker.callBaseMethod(this, 'initialize');
        $addHandlers(this._partiesDDLElement, { "change": this._selectedPartyChangedHandler }, this);

But since the radcombo isn't a html dom object, I can't attach the event this way and every other thing I've tried has failed. How do I tell the radcombo in my custom control, on the client, what to execute when the radcombo's selected item changes? I don't seem to be able to get a reference to the client side radcombo object. Remember this is a custom control so I need to always reference a function of this, my, control. Thanks !

4 Answers, 1 is accepted

Sort by
0
Keith Thorne
Top achievements
Rank 1
answered on 31 Mar 2010, 03:14 PM

I'm trying to use:
       var combo = $find("<%= RadComboBox1.ClientID %>");
I pass the client id as a property to my control via the server side AddProperty method of IScriptControl. I can see the value on the client and it looks right. So then i pass this value to the client $find() only to have it return null. What am I doing wrong?
      descriptor.AddProperty("myRadComboClientID", drpIdRadCombo.ClientID);


in the javascrip "initialize" for my control but still no luck in getting to the radcombo object. I can see
MyControlNS.MyControl.prototype = {
    initialize: function() {
    MyControlNS.MyControl.callBaseMethod(this, 'initialize');

I could really use some help if anyone has ideas. Thanks!
        
0
Keith Thorne
Top achievements
Rank 1
answered on 31 Mar 2010, 04:05 PM
More info, I think the problem may be related to the fact that the radCombo doesn't exist during the $createf() client call for my custom control. I need something that occurs after the control is created to assign the ClientSelectedIndexedChanged on the radCombo. For sure someone has done this before, any help?
0
Simon
Telerik team
answered on 01 Apr 2010, 11:43 AM
Hello Keith Thorne,

You can set the OnClientSelectedIndexChanged property of the RadComboBox (server-side) to the name of the client-side function to execute when an Item is selected.

Does this fit your implementation?

Best wishes,
Simon
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Accepted
Keith Thorne
Top achievements
Rank 1
answered on 01 Apr 2010, 02:13 PM
That wasn't the problem. But after much head beating against the wall I discovered what I needed was the client side delegate.  With the delegate the context is correct and the execution occurs only when the initialization has completed. For example:

MyControlNS.MyControl= function(element) {
   MyControlNS.MyControl.initializeBase(this, [element]);
    this._txtBxAddr1;
    this._txtBxAddr2;
    this._txtBxCity;
    this._txtBxState;
    this._txtBxPostalCode;
    this._txtBxCountry;
    Sys.Application.add_load(Function.createDelegate(this, MyControlNS.MyControl.onLoaded));
}

MyControlNS.MyControl.onLoaded = function() {
   $find(this._myControlRadComboClientID).add_selectedIndexChanged(this._tempItemChanged);
}


Tags
ComboBox
Asked by
Keith Thorne
Top achievements
Rank 1
Answers by
Keith Thorne
Top achievements
Rank 1
Simon
Telerik team
Share this question
or