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

OnclientClosing does not fire in Radcombobox control

1 Answer 28 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Prathap
Top achievements
Rank 1
Prathap asked on 08 May 2012, 06:50 PM
Hi
I am using radcombobox with checkbox options.
I need onclientclosing event to be fired for a web part.
I was able to achieve this using aspx page as shown below

aspx
<telerik:RadComboBox ID="cmbSites" CheckBoxes="true" EnableCheckAllItemsCheckBox="true"  runat="server" HighlightTemplatedItems="true" MaxHeight="200" EmptyMessage="+ Select Site +"
                        width="300px" Skin="MySkin_Default" EnableEmbeddedSkins="false" OnClientDropDownClosing="HandleCloseSite" />
java script
function HandleClose(combo) {
          var items = combo.get_items();
          var csv = "";
          for (i = 0; i < items.get_count(); i++) {
              var chk = getItemCheckBox(items.getItem(i));
              if (chk != null && chk.checked) csv += "," + items.getItem(i).get_value();
          }
          if (csv.length > 2) {
              return csv.substring(1);
          }
          else
              return combo.get_value();
      }
Now I need write the same code in code behind for a web part.
in createchildcontrols I am declaring the radcombobox
            cmbChildEntities = new RadComboBox();
            cmbChildEntities.Visible = true;
            cmbChildEntities.AutoPostBack = true;
            cmbChildEntities.EnableCheckAllItemsCheckBox = true;
            cmbChildEntities.HighlightTemplatedItems = true;
            cmbChildEntities.CheckBoxes = true;
            cmbChildEntities.Width = 275;
            cmbChildEntities.EnableEmbeddedSkins = false;
            cmbChildEntities.Skin = "MySkin_Default";
           
In render I have a javascript call
 string js;
                js = "function HandleCloseRegion(){\n";
                js += "alert('test.');\n";
                js += "}\n";

                Page.ClientScript.RegisterStartupScript(this.GetType(), "PIROptions", js, true);
            

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 11 May 2012, 11:39 AM
Hi Prathap,

Here is how you could create RadComboBox dynamically and register its client event handlers on the page as well:
protected void Page_PreInit(object sender, EventArgs e)
{
    RadComboBox combo = new RadComboBox();
    combo.ID = "RadComboBox1";
    combo.CheckBoxes = true;
    combo.EnableCheckAllItemsCheckBox = true;
    combo.AutoPostBack = false;
    combo.HighlightTemplatedItems = true;
 
    combo.Items.Add(new RadComboBoxItem("111", "111"));
    combo.Items.Add(new RadComboBoxItem("222", "222"));
    combo.Items.Add(new RadComboBoxItem("333", "333"));
    combo.Items.Add(new RadComboBoxItem("444", "444"));
    combo.Items.Add(new RadComboBoxItem("555", "555"));
 
    combo.OnClientDropDownClosing = "HandleCloseRegion";
 
    string hanldeCloseRegion = @"function HandleCloseRegion(sender, args){
          var csv = '';
          sender.get_checkedItems().forEach(function(item, index){
            csv += ',' + item.get_value()
          });
          if (csv.length > 2) {
              alert(csv.substring(1));
          }
          else
              alert(sender.get_value());
        }";
 
    form1.Controls.Add(combo);
     
    ScriptManager.RegisterClientScriptBlock(this, GetType(), "handler", hanldeCloseRegion, true);
}

I hope this will help.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
General Discussions
Asked by
Prathap
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or