FindWindowByID

2 posts, 0 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 16 May 2011 Link to this post

    I need to test whether or not a RadWindow is in the Windows collection of a RadWindowManager.

    "Easy" I thought, I'll add an extension method ...

    public static RadWindow FindWindowByID(this RadWindowManager WindowManager, string ID)
    {
        if (String.IsNullOrWhiteSpace(ID))
        {
            throw new InvalidOperationException("Searching for a blank ID is not supported)");
        }
        string id = ID.ToLower();
        if (WindowManager.Windows.Count == 0)
        {
            return null;
        }
        RadWindow result = null;
        foreach (RadWindow window in WindowManager.Windows)
        {
            if (window.ID.ToLower() == id)
            {
                result = window;
                break;
            }
        }
        return result;
    }

    However, when called it always throws an exception in the test if(window.ID.ToLower() == id) and reports the window.ID is null.

    If I drill down through the object's structure all the way to WebControl I can see that, in fact, ID is set but it isn't my value (the one assigned in the markup), but, rather is an automagically assigned value like cl001.

    OK, so you are managing the ID, but I can't find a property anywhere that has the value that I assigned and that I can test against.

    What am I missing?

    -- 
    Stuart
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 17 May 2011 Link to this post

    Hi Stuart,

    The most likely cause is that the RadWindowManager is inside an INaming container and thus the IDs of the controls inside are changed by the framework.

    For your convenience I created and attached a simple page illustrating the approach. The logic is quite simplified and would throw exceptions without some defensive programming, yet it is the basic concept that should work regardless.

    Please make sure that you have a correct reference to the RadWindowManager and that its collection is not empty, so that you can iterate through it, although it is doubtful that the page would compile if that were the case.

    On a side note - there is a RadWindowManager's client-side method that returns a reference to the desired RadWindow by its id: getWindowById() and radopen(null, [ID]) would return the same, too.

    If the above does not help you resolve the situation please send us a simple project that isolates this behavior so we can debug it on our end and provide a more to the point answer, as your code seems to be working fine on my end right now.



    All the best,
    Marin
    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
Back to Top