This is a migrated thread and some comments may be shown as answers.

FindWindowByID

1 Answer 64 Views
Window
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 16 May 2011, 10:18 AM
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

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 17 May 2011, 02:54 PM

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.

Tags
Window
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Marin Bratanov
Telerik team
Share this question
or