RadComboBox client events in 2015.2.826.45

1 Answer 15 Views
ComboBox
Rob
Top achievements
Rank 1
Rob asked on 19 Mar 2024, 09:36 PM

This is probably just a request for a pointer to the documentation for older versions, which I couldn't find.  But the problem that I'm trying to solve is:

I'm trying to update some older software that uses Telerik.Web.UI 2015.2.826.45.  I'd like to add a client-side event handler that fires whenever the value of a RadComboBox is changed, whether by the user, or by server-side code.  The current doco quite clearly states that I want to use add_selectedIndexChanged, with the eventArgs parameter which is passed to that event containing the new selected item.  That function doesn't seem to exist in the version I'm using.  I tried adding a handler via the OnClientSelectedIndexChanged attribute of the ASPX element, and it handles an event when the user makes a change, but not when the server does.  And the arguments are in a completely different form.  Any idea how I do something equivalent in the older version?  Or where to find documentation that would apply to that version?

 

Thanks for any help

 

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 22 Mar 2024, 09:35 AM

Hi Rob,

The documentation focuses mainly on the current version, but the API you are using is not touched. You can go through the changes in the releases at https://www.telerik.com/forums/known-issues-and-important-changes and you will find that there aren't any breaking or regression changes in the combobox API between 2015 and 2024. 

You can for example use the OnClientLoad event of the RadComboBox to attach a client-side event handler to the RadComboBox. Here is an example code snippet:

<telerik:RadComboBox ID="RadComboBox1" runat="server" RenderMode="Lightweight" OnClientLoad="onClientLoad">
    <Items>
        <telerik:RadComboBoxItem Text="Item 1" />
        <telerik:RadComboBoxItem Text="Item 2" />
        <telerik:RadComboBoxItem Text="Item 3" />
        <telerik:RadComboBoxItem Text="Item 4" />
    </Items>
</telerik:RadComboBox>
<script>
    function onClientLoad(sender, args) {
        sender.add_selectedIndexChanged(handler1);
        sender.add_selectedIndexChanged(handler2);
    }
    function handler1(sender, args) {
        alert("first handler fired");
    }
    function handler2(sender, args) {
        alert("second handler fired");
    }
</script>

Please note that this approach may not work if the server-side code changes the value of the RadComboBox after the page has been loaded. In that case, you may need to use a different approach.

 The OnClientSelectedIndexChanged (add_selectedIndexChanged) event is not firing for server-side changes, this behavior is typically by design for client-side events. To work around this, you could trigger the client-side event manually after your server-side code makes a change to the RadComboBox. You can do this by using a small snippet of JavaScript to mimic the user changing the selection. For example, after updating the RadComboBox on the server-side, you might register a startup script (using ScriptManager.RegisterStartupScript or Page.ClientScript.RegisterStartupScript) that explicitly calls the client-side change handler you have attached via OnClientSelectedIndexChanged.

Additionally, it is crucial to upgrade the Telerik.Web.UI.dll version in your app to at least 2020.1.114 or even better the latest one since the versions before 2020.1.114 are vulnerable to some critical vulnerabilities. You can find information in this article: https://docs.telerik.com/devtools/aspnet-ajax/knowledge-base/common-allows-javascriptserializer-deserialization

 

Regards,
Rumen
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
ComboBox
Asked by
Rob
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or