injecting combobox client event handler from code behind

3 posts, 0 answers
  1. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 12 Feb 2013 Link to this post

    Hello !

    I am trying to 'detect' if change is made to my page, containing telerik and 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 + ");"))

    ( 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 + ");"));



    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. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 13 Feb 2013 Link to this post

    Can anyone please help me out here ?
  3. Hristo Valyavicharski
    Hristo Valyavicharski avatar
    975 posts

    Posted 14 Feb 2013 Link to this post

    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) {
             .ForEach(radTb => radTb.ClientEvents.OnValueChanged = "noticeChange");
             .ToList().ForEach(radTb => radTb.ClientEvents.OnKeyPress = "noticeChange");
             .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.
Back to Top