OnClient Event firing on pageload

2 posts, 0 answers
  1. Marcus
    Marcus avatar
    2 posts
    Member since:
    Jul 2013

    Posted 30 Jul 2013 Link to this post

    Hi
    I'm having trouble implementing a RadComboBox. The thing I would like to do is to save a temporary state of which checkboxes that where checked when the dropdown list first was opened. The state should then be used to restore the checked checkboxes if the user click on a cancel button.  To do this have I tried the following code.
    <telerik:RadComboBox ID="RadComboBox1" Runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" Localization-CheckAllString="Select all"
        EmptyMessage="Select" AutoPostBack="false" LabelCssClass="MultipleChoiceLabels" DropDownCssClass="MultipleChoiceLabels"
        OnClientItemChecked="SaveState('ucMCDFilterByIAI_RadComboBox1')">
    </telerik:RadComboBox>

    function SaveState(DropDownID) {
        var combo = $find(DropDownID);
        var state = new Array();
        var items = combo.get_items();
        var itemCount = items.get_count();
        for (var counter = 0; counter < itemCount; counter++) {
            var item = items.getItem(counter);
        }
    }

    The problem I'm experience is that when the page loads, the SaveState method is called. This is not what was intended. Even worse is that $find(DropDownID) is returning null and therefore breaks the whole function. The function is working as it should if I hook up it to a button that is called after the page has loaded. Any suggestions on what whats wrong and what to do?
  2. Marcus
    Marcus avatar
    2 posts
    Member since:
    Jul 2013

    Posted 30 Jul 2013 Link to this post

    Found the answer to my problem here http://blogs.telerik.com/aspnet-ajax/posts/12-08-10/migrating-onclientclick-handlers-from-asp-button-to-telerik-s-asp-net-ajax-button.aspx. The problem was that I had parentheses in the ClientEvent. Telerik events should not be provided with any parentheses. When I took those away, everything started to work as expected.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top