Community
Showing results for 
Search instead for 
Do you mean 
Reply

Making your Custom Control only do it's magic when visible on the layout.

Copper Contributor
Posts: 61
Country: USA

Making your Custom Control only do it's magic when visible on the layout.

Published 15 July 07 08:55 PM

I am working on an update to the ContactWebContextBrowser control where it would only fetch the web site pages if visible (this way, If you have 15 or more web site tabs on your layouts it is not trying to load all of them when switching contacts).  Anyway, the solution was rather simple, and that was largely because the TabControl already sets the visible property of any controls not shown to false.  So, all I had to do was to make sure I do not fetch the URL unless it is visible.  I also had to add an event handler to make sure that the URL is fetched if the user makes the control visible (presumably by selecting the Tab).

Anyway, thought I'd share the changes, as it will be a few more days before I can post an update, since I had feedback that some users like it the way it is, so I will have to add this "fetch only on visible" feature as n option rather than the only way.

Hope this helps

 

private void GetURL()
{
   // only fetch the URL if the control (this) is visible
   if (this.Visible == true)
   {
      if (currentContact != null)
      {
         // build the URL to navigate to
        
BuildResolvedURL();
        // navigate to that URL
        this.FetchAddress();
      }
   }
}

// make sure we call GetURL if the visibility of the control is changed. Note, since we are overriding this internal protected method
// we do not have to explicitly do any event hooking.
// also note that we call the base handler to make sure other handlers listening to the event are called.
protected override void OnVisibleChanged(EventArgs e)
{
  
base.OnVisibleChanged(e);
   GetURL();
}