List item visibility after postback

6 posts, 0 answers
  1. Rob
    Rob avatar
    4 posts
    Member since:
    Nov 2010

    Posted 08 Feb 2011 Link to this post

    Hi,

    I have a RadListBox with a filter where I set the visibility of items based on the filter, however when I do a postback on SelectedIndexChanged on the RadListBox it loses the visibility set on the list items so that invisible items become visible again after the postback. It's in a user control so I don't have access to the body onload to filter the list again. I have tried onload on other controls but I get an error and I'm not sure why. Does anyone have a suggestion as to how I can keep these list items invisible after a postback?

    Thanks.
  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 12 Feb 2011 Link to this post

    Hello Rob,

    If you make any changes to a control on the client-side and you want to persist these changes after post back you should call trackChanges() and commitChanges() methods of the particular control.
    In your case you shoud call trackChanges method before you start editing the visibility of the items and when you are finished editing, you should call commitChanges method.
    More information you could find here.

    Greetings,
    Dimitar Terziev
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rob
    Rob avatar
    4 posts
    Member since:
    Nov 2010

    Posted 17 Feb 2011 Link to this post

    Unfortunately this didn't work. The items still show again after a postback. Not sure what i'm doing wrong.
  5. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 21 Feb 2011 Link to this post

    Hello Rob,

    Could you show me your code, where you are setting the visibility of the listbox items.
    This way it would be easy to check what is causing the problem you are experiencing.
    In general there should be no problems setting certain changes on the client side and persisting them after post-back, when  trackChanges and commitChanges are used.

    Kind regards,
    Dimitar Terziev
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  6. Rob
    Rob avatar
    4 posts
    Member since:
    Nov 2010

    Posted 21 Feb 2011 Link to this post

                #region JavaScript
                var script = @"<script type=""text/javascript"">

                    // Filter the list of users and ephasise the matching characters in the user items.
                    function FilterUsers() {
                                           
                        var userList = $find(""" + UserSelectionControl.ClientID + @""");
                        var filterBox = document.getElementById(""" + UserFilterControl.ClientID + @""");
                        var filter = filterBox.value;
                        userList.trackChanges();
                        ClearListEmphasis(userList);
                        FilterList(userList, filter);
                        userList.commitChanges();
                    }

                    // Filter a list of items and ephasise the matching characters in the items.
                    function FilterList(list, filter) {
                        var items = list.get_items();
                        items.forEach
                        (
                            function (item) {
                                var itemText = item.get_text();
                                if (itemText.toLowerCase().indexOf(filter.toLowerCase()) != -1) {
                                    var regFilter = filter.replace(""\\"",""\\\\""); // Escape the back slashes and brackets.
                                    regFilter = regFilter.replace("")"",""\\)"");
                                    regFilter = regFilter.replace(""("",""\\("");

                                    var regEx = new RegExp(regFilter, ""i"");                
                                    item.set_text(itemText.replace(regEx, ""<em>"" + itemText.match(regEx) + ""</em>"")); // See sims.css for emphasis style.
                                    item.set_visible(true);
                                }
                                else {
                                    item.set_visible(false);
                                }
                            }
                        )
                    }

                    // Clear the emphasis from any matching characters in the list.
                    function ClearListEmphasis(list) {
                        var regEx = new RegExp(""</{0,1}em>"", ""gi"");
                        var items = list.get_items();
                        var itemText;

                        items.forEach
                        (
                            function (item) {
                                itemText = item.get_text();
                                item.set_text(itemText.replace(regEx, """"));
                            }
                        )
                    }

                    // Show a water mark in the search text boxes.
                    var defaultText = ""Search..."";
                    function WaterMark(txt, evt) {
                        if (txt.value.length == 0 && evt.type == ""blur"") {
                            txt.style.color = ""gray"";
                            txt.value = defaultText;
                        }
                        if (txt.value == defaultText && evt.type == ""focus"") {
                            txt.style.color = ""black"";
                            txt.value = """";
                        }
                    }
                </script>    ";
                #endregion

  7. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 24 Feb 2011 Link to this post

    Hi Rob,

    After further investigation on this problem, it seems that these changes are not persisted on the server side in purpose. The general idea is that if you set that a particular item won't be visible and persist this change, the next time when the page is loaded this item won't be rendered. This will make a big confusion if you then try to make it again visible, because this item won't be physically present in the listbox items collection. This is why this visibility change is ignored by the server. As a solution to this constrain you may save the indexes of the items which has been invisible in a hidden field and when the page is loaded , subscribe on the client-side  pageLoad event and again set them to be invisible.


    Regards,
    Dimitar Terziev
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017