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

[Solved] RadComboBox in custom server control

4 Answers 234 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kevin Kembel
Top achievements
Rank 1
Kevin Kembel asked on 19 Apr 2009, 11:43 PM
I'm looking to add a RadComboBox to a custom server control (a custom WebPart CatalogPart control).  Basically, my webpart catalog pulls a directory from a database, and I want to use the properties to populate the RadComboBox for the user to select the desired WebPart.

What do I need to do in order to declare a new instance of a RadComboBox programmatically, and to add items to it manually?

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 20 Apr 2009, 12:52 PM
Hi Kevin Kembel,

You can use RadCombox from code behind as any other server control:

  1. Instantiate a new instance of the RadComboBox class
  2. Add it to the controlls collection
  3. Add items to the combobox and subscribe to events
You also need a ScriptManager control added in your page. Please check this step by step tutorial for creating Ajax enabled web part using RadControls. The demo utilizes RadTreeView but the approach is similar.
Regards,
Albert
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
Kevin Kembel
Top achievements
Rank 1
answered on 26 Apr 2009, 01:14 AM
After reviewing your link, and what you'd said, I'm still having some issues (but getting closer).  I'll be more specific.

I have a custom CatalogPartChrome for my webpart portal.  Rather than displaying a bunch of checkbox items like the standard catalogpartchrome, it displays all of the items in a DropDownList, to easily select webparts, and this works fine for me.  I wanted to expand the functionality from a DropDownList to a RadComboBox to add a better look and feel, images, etc...

I should also mention that all of my webpart controls are wrapped in an ajax UpdatePanel (which seems to be behaving well).

The relevant parts of my code are:

 

public class MyCustomCatalogPartChrome : CatalogPartChrome

{

    RadComboBox catalogComboBox;

    ScriptManager pageScriptManager;

 

    public MyCustomCatalogPartChrome(MyCustomCatalogZone zone)

        : base(zone)

    {

        // As per the how-to that I was shown in the previous post, 
        // although I'm not sure if it's implemented c
orrectly in 
        // this case, as this isn't a normal WebControl

        this.Zone.Page.ClientScript.RegisterStartupScript(

            typeof(CatalogZone), this.Zone.ID,

            "_spOriginalFormAction = document.forms[0].action;
                _spSuppressFormOnSubmitWrapper=true;"
,
            true);

 

 

        if (this.Zone.Page.Form != null)

        {

            string formOnSubmitAtt = 
                this.Zone.Page.Form.Attributes["onsubmit"];

            if (!string.IsNullOrEmpty(formOnSubmitAtt) &&

 

                formOnSubmitAtt == "return _spFormOnSubmitWrapper();")

            {

                this.Zone.Page.Form.Attributes["onsubmit"] = 
                    "_spFormOnSubmitWrapper();";

            }


        }

        
        pageScriptManager = ScriptManager.GetCurrent(this.Zone.Page);

 

    }

 

    public override void PerformPreRender()

    {

        base.PerformPreRender();

 

        catalogComboBox = new RadComboBox();

        catalogComboBox.ID = "uxCatalogComboBox";

        catalogComboBox.Page = this.Zone.Page;

 

        // Need to register the control with the scriptmanager, or a 
        // runtime error occurs

        pageScriptManager.RegisterScriptControl<RadComboBox>(
            catalogComboBox);

 

 

        catalogComboBox.Items.Add(new RadComboBoxItem("Item #1", "1"));

        catalogComboBox.Items.Add(new RadComboBoxItem("Item #2", "2"));

        catalogComboBox.Items.Add(new RadComboBoxItem("Item #3", "3"));

        catalogComboBox.Items.Add(new RadComboBoxItem("Item #4", "4"));

    }

 

    public override void RenderCatalogPart(HtmlTextWriter writer, 
        CatalogPart catalogPart)

 

    {

        // Normally there's a bunch of extra code here to render 
        // all of the available web parts,

        // but it's all removed to simplify this problem

        catalogComboBox.RenderControl(writer);

    }

}

 

 

 

 

 

 

 

So, what happens in this case is, everything executes seeminly fine, and there is an empty radcombo box displayed in the my catalog control.  Beside the empty list, is the text "select".  I can click on the empty list, or click on select, but nothing happens.

When I review the elements created in firebug or ie developer toolbar, everything looks like it's there, it's just not displaying correctly.

 

 

 

 

 

<div id="uxCatalogComboBox" class="RadComboBox RadComboBox_Default" 
    style="width: 160px; display: -moz-inline-stack;"
>
    <table cellspacing="0" cellpadding="0" border="0" style="border-width: 0pt;" 
        summary="combobox"
>
        <tbody>
        <tr class="rcbReadOnly">
            <td class="rcbInputCell rcbInputCellLeft" style="width: 100%;">
                <input id="uxCatalogComboBox_Input" class="rcbInput" type="text" style="" 
                    readonly="readonly"
 value="" name="uxCatalogComboBox"/>
            </td>
            <td class="rcbArrowCell rcbArrowCellRight">
                <a id="uxCatalogComboBox_Arrow" style="overflow: hidden; display: block; 
                     position: relative; outline-color: invert;
                     outline-style: none; outline-width: medium;
"
>select</a>
            </td>
        </tr>
        </tbody>
    </table>
    <div class="rcbSlide" style="z-index: 6000;">
        <div id="uxCatalogComboBox_DropDown"     
            class="RadComboBoxDropDown RadComboBoxDropDown_Default"
 
            style="display: none;"
>
            <div class="rcbScroll rcbWidth" style="width: 100%;">
                <ul class="rcbList" style="margin: 0pt; padding: 0pt; list-style-type: none; 
                    list-style-image: none; list-style-position: outside;
"
>
                    <li class="rcbItem">Item #1</li>
                    <li class="rcbItem">Item #2</li>
                    <li class="rcbItem">Item #3</li>
                    <li class="rcbItem">Item #4</li>
                </ul>
            </div>
        </div>
    </div>
    <input id="uxCatalogComboBox_ClientState" type="hidden" 
        name="uxCatalogComboBox_ClientState"
/>
</div>

Any ideas?

 

 

 

 

0
Accepted
Atanas Korchev
Telerik team
answered on 27 Apr 2009, 01:50 PM
Hello Kevin Kembel,

You need to add the combobox control to the controls collection of your web part. Otherwise RadComboBox will not render its skin CSS file and the JavaScript files.

Regards,
Albert
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
Kevin Kembel
Top achievements
Rank 1
answered on 28 Apr 2009, 04:36 AM
Thanks for the help, that ended up working.

For the record in case anyone else has this problem, it was a little tricky given how the CatalogPartChrome and CatalogPart works (unless I'm missing something obvious):

I couldn't add it to the control collection of the catalogPart, since the only access to the catalogPart was in the RenderCatalogPart(HtmlTextWriter, CatalogPart) method of the CatalogPartChrome, and you can't modify the collection after PreRender (but there is no way to access the catalogPart in the PreRender method).

I couldn't add it to the control collection of the CatalogPartChrome because it doesn't have a control collection, so in the PerformPreRender() method, I tried adding the RadComboBox to the CatalogZone (CatalogPartChrome.Zone), and it worked fine.

Thanks again,

Kevin
Tags
ComboBox
Asked by
Kevin Kembel
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Kevin Kembel
Top achievements
Rank 1
Share this question
or