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

injecting combobox client event handler from code behind

2 Answers 211 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Aarsh
Top achievements
Rank 1
Aarsh asked on 12 Feb 2013, 07:45 PM
Hello !

I am trying to 'detect' if change is made to my page, containing telerik and asp.net controls.RadTextboxes behave as expected Code beneath the one for DropDownList does not work. I tried to have just a simple alert but though radComboBox does not seem to be playing fair ...

I am using traditional ASP.NET master/content page scenario. And the content page loads up as a radTab of a master page.

RadTextBox ( Works ! )
    ControlExtension.All(this.Controls).OfType<RadTextBox>().ToList().ForEach(radTb => radTb.Attributes.Add("onchange", "noticeChange(" + radTb.ClientID + ");"));
ControlExtension.All(this.Controls).OfType<RadTextBox>().ToList().ForEach(radTb => radTb.Attributes.Add("onkeydown", "noticeChange(" + radTb.ClientID + ");"))

DropDownList
( Works ! )
    ControlExtension.All(this.Controls).OfType<DropDownList>().ToList().ForEach(dd => dd.Attributes.Add("onChange", "noticeChange(" + dd.ClientID + ");"));
ControlExtension.All(this.Controls).OfType<DropDownList>().ToList().ForEach(dd => dd.Attributes.Add("onselectedindexchanged", "noticeChange(" + dd.ClientID + ");"));

RadComboBox ( Doesn't )
    ControlExtension.All(this.Controls).OfType<RadComboBox>().ToList().ForEach(radDd => radDd.Attributes.Add("onclientselectedindexchanging", "noticeChange(" + radDd.ClientID + ");"));
ControlExtension.All(this.Controls).OfType<RadComboBox>().ToList().ForEach(radDd => radDd.Attributes.Add("OnClientSelectedIndexChanged", "noticeChange(" + radDd.ClientID + ");"));
ControlExtension.All(this.Controls).OfType<RadComboBox>().ToList().ForEach(radDd => radDd.Attributes.Add("onclienttextchange", "noticeChange(" + radDd.ClientID + ");"));


Thanks,
-Aarsh

Added

I tried following, just in the case if you're wanting to suggest. It did not worked. The above approach at least added an attirb when I observed in F12 of IE9 but this guy do not seem to be working.

Additionally, it behaves as if it has a JavaScript error

(my radTab do not fill out in the screen upon JavaScript error, if I use the code posted underneath, this happened, so ... )

ControlExtension.All(this.Controls).OfType<RadComboBox>().ToList().ForEach(radDd => radDd.OnClientSelectedIndexChanged = "noticeChange(" + radDd.ClientID + ")");
ControlExtension.All(this.Controls).OfType<RadComboBox>().ToList().ForEach(radDd => radDd.OnClientTextChange = "noticeChange(" + radDd.ClientID + ");");

2 Answers, 1 is accepted

Sort by
0
Aarsh
Top achievements
Rank 1
answered on 13 Feb 2013, 12:10 PM
Can anyone please help me out here ?
0
Hristo Valyavicharski
Telerik team
answered on 14 Feb 2013, 04:28 PM
Hi Aarsh,

Change the noticeChange function to have two parameters sender and args. Do not pass control ID to this function. You can get it from sender.get_id():

function noticeChange(sender, args) {
    alert(sender.get_id());
}
ControlExtension
         .All(this.Controls)
         .OfType<RadTextBox>()
         .ToList()
         .ForEach(radTb => radTb.ClientEvents.OnValueChanged = "noticeChange");
 
     ControlExtension
         .All(this.Controls)
         .OfType<RadTextBox>()
         .ToList().ForEach(radTb => radTb.ClientEvents.OnKeyPress = "noticeChange");
 
     ControlExtension
         .All(this.Controls)
         .OfType<RadComboBox>()
         .ToList()
         .ForEach(radCb => radCb.OnClientSelectedIndexChanged = "noticeChange");

All the best,
Hristo Valyavicharski
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
ComboBox
Asked by
Aarsh
Top achievements
Rank 1
Answers by
Aarsh
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or