How can I share data between multiple user controls?

I have 3 user controls, each of which will have to retrieve data from an XML feed based on various URL parameters, etc. Now the data in this XML feed will be the same for all 3 user controls, because they all send the same request.

It seems foolish to make 3 separate requests for what will be identical data.

My idea is to have one singleton, which I will name, that will execute one request to the XML service, and then present well-parsed results for user controls.

i.e:.

  • User Control A captures singleton.
  • User Control A asks Singleton to make a request ...
  • Singleton makes a request and parses XML in various properties.
  • C user control captures a singleton and retrieves data.
  • User Control A pulls its data from a singleton.
  • User control B captures the singleton and pulls out its data.

Now that I’m thinking about it, I need to add some kind of lock to the “make a request” method so that I do not call it several times at the same time - I am new to C #, what is the easiest way to do this? Are user controls controlled at the same time? Is there a good review for this somewhere?

: " #?", , : " ", " ?" " , ?".

+3
3

, , , ( ).

XML , , - :

public class Page : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        string data = DoXMLRequest();
        ucControl1.Data = data;
        ucControl2.Data = data;
        ucControl3.Data = data;
    }
}

, , XML- ( ).

:

OnLoad Page, . .

: ASP.NET ( ).

+6

singleton #?

. , , . - . ( ), HttpCache ( - ) , , ( ) . , Page_Load, MattMitchell.

+1
+1
source

All Articles