Advice Needed: Three Web controls talk to each other?

Discussion in 'ASP .Net Web Controls' started by George Leithead, Jun 28, 2006.

  1. Hi all,

    I have a requirement to implement a Search Interface component. I
    would like to implement this using three different components, for
    maximum flexibility.

    The first two are "Basic" search and "Advanced Search". Both will use
    the same back-end logic to put the search together. I'm using a
    WebControl for both of these and overriding the CreateChildControls to
    composite controls together (textbox, button, etc.).

    The third component would be the "Search Results" component. I want to
    base this control on a DataGrid.

    The advice I need is how to get the search query from either of the
    first two components to the Search Results component? I would like for
    the Search Results to 'listen' for an event from one of the other two
    components. How do I go about this? I don't want to have to put code
    into the ASPX page to handle the communication between the two
    controls.

    Any advice, and direction of examples (in C#) would be fantastic and
    much appreciated.

    George
    George Leithead, Jun 28, 2006
    #1
    1. Advertising

  2. George Leithead

    Doug Salomon Guest

    You said : "I don't want to have to put code into the ASPX page to handle the
    communication between the two controls."

    I think that you probably _should_ put that kind of code into the page
    hosting the controls. the advantage to doing this is that your user controls
    end up being more generic and hence more reusable in different scenarios.

    Also, this is, more or less how the built in controls work. Consider the
    following example : You have a page with a buton and a textbox. Clicking the
    button causes "Hello World" (of course) to appear in the textbox.

    The button and the textbox know nothing about each other. It is code on the
    hosting page which handles the click event of the button and assigns the
    words "Hello World" to the textbox's text property.

    If the creator of the button and textbox had linked those two controls, then
    they wouldn't be able to do much more than populate the textbox on click.

    Just my opinion, but I hope it helps,
    Doug

    "George Leithead" wrote:

    > Hi all,
    >
    > I have a requirement to implement a Search Interface component. I
    > would like to implement this using three different components, for
    > maximum flexibility.
    >
    > The first two are "Basic" search and "Advanced Search". Both will use
    > the same back-end logic to put the search together. I'm using a
    > WebControl for both of these and overriding the CreateChildControls to
    > composite controls together (textbox, button, etc.).
    >
    > The third component would be the "Search Results" component. I want to
    > base this control on a DataGrid.
    >
    > The advice I need is how to get the search query from either of the
    > first two components to the Search Results component? I would like for
    > the Search Results to 'listen' for an event from one of the other two
    > components. How do I go about this? I don't want to have to put code
    > into the ASPX page to handle the communication between the two
    > controls.
    >
    > Any advice, and direction of examples (in C#) would be fantastic and
    > much appreciated.
    >
    > George
    >
    >
    Doug Salomon, Jun 28, 2006
    #2
    1. Advertising

  3. I would create a SearchCriteria class to hold all the options for the
    search.

    The basic and advanced search controls would share the same instance of
    SearchCriteria so that they can both set values in it, and a change in
    one would be displayed in the other.

    This same SearchCriteria instance could then be passed to search results
    control so that the search results can view the output.

    Lastly there can be some kind of perform search method within the
    SearchCriteria class that queries the DB, fetches the results and raises
    an event to say that it has a new search waiting. The search control can
    subscribe for this event and rebind itself with the new data, this
    should make it easy to have a button that performs the search on both
    the basic and advanced controls.

    Lastly you need to glue all this together, if you don't want it in the
    ASPX page you're going to need an ASCX or something that will contain
    the basic, advanced and results controls. This glue control will be the
    one that is responsible for persisting the search criteria object (by
    saving it to the viewstate or something). It will also handle the
    switching between the basic, advanced, and results controls.

    This should allow the three different parts to work together whilst
    remaining de-coupled.

    Although the only reason for not making the ASPX page the 'glue' control
    that I can see is if you wanted to use the search control on other
    pages. For this to be of much use you'd have to look at a more generic
    solution as to how you create your basic and advanced search pages if
    you wanted to reuse the same search control for any search.


    Note, this may not be the best solution, I've just typed this up as I've
    thought of it but maybe it can give you some ideas.


    On Wed, 28 Jun 2006 06:31:01 -0700, Doug Salomon
    <> wrote:

    >You said : "I don't want to have to put code into the ASPX page to handle the
    > communication between the two controls."
    >
    >I think that you probably _should_ put that kind of code into the page
    >hosting the controls. the advantage to doing this is that your user controls
    >end up being more generic and hence more reusable in different scenarios.
    >
    >Also, this is, more or less how the built in controls work. Consider the
    >following example : You have a page with a buton and a textbox. Clicking the
    >button causes "Hello World" (of course) to appear in the textbox.
    >
    >The button and the textbox know nothing about each other. It is code on the
    >hosting page which handles the click event of the button and assigns the
    >words "Hello World" to the textbox's text property.
    >
    >If the creator of the button and textbox had linked those two controls, then
    >they wouldn't be able to do much more than populate the textbox on click.
    >
    >Just my opinion, but I hope it helps,
    >Doug
    >
    >"George Leithead" wrote:
    >
    >> Hi all,
    >>
    >> I have a requirement to implement a Search Interface component. I
    >> would like to implement this using three different components, for
    >> maximum flexibility.
    >>
    >> The first two are "Basic" search and "Advanced Search". Both will use
    >> the same back-end logic to put the search together. I'm using a
    >> WebControl for both of these and overriding the CreateChildControls to
    >> composite controls together (textbox, button, etc.).
    >>
    >> The third component would be the "Search Results" component. I want to
    >> base this control on a DataGrid.
    >>
    >> The advice I need is how to get the search query from either of the
    >> first two components to the Search Results component? I would like for
    >> the Search Results to 'listen' for an event from one of the other two
    >> components. How do I go about this? I don't want to have to put code
    >> into the ASPX page to handle the communication between the two
    >> controls.
    >>
    >> Any advice, and direction of examples (in C#) would be fantastic and
    >> much appreciated.
    >>
    >> George
    >>
    >>
    Chris Chilvers, Jun 28, 2006
    #3
  4. All,

    I have managed to do what I wanted to do! The first control UIa and
    second control UIb both call SearchResults. This is done through the
    following:

    In the UIa class
    ===========
    public delegate void SearchEventHandler(object sender,
    SearchActivatedEventArgs e);
    ....
    _SearchButton.Click += new EventHandler(_button_Click);

    ....
    private void _button_Click(object source, EventArgs e)
    {
    ...
    // Go through the collection of controls in the page, and make sure
    that there is a SearchResults control to Call!
    foreach (Control ctrl in Page.Controls)
    {
    foreach (Control chldControl in ctrl.Controls)
    {
    if (chldControl.GetType() == typeof(myControlLibrary.SearchResults))
    ((myControlLibrary.SearchResults)chldControl).PerformSearch(this, new
    SearchActivatedEventArgs(queryExpression, InstanceName,
    CollectionNames, useWildcards));
    }
    }
    }

    In the SearchActivatedEventArgs.cs class
    ==============================
    public class SearchActivatedEventArgs : EventArgs
    {
    public SearchActivatedEventArgs(string inqueryExpression, string
    inInstanceName, string inCollectionNames, bool inuseWildCards)
    {
    queryExpression = inqueryExpression;
    InstanceName = inInstanceName;
    CollectionNames = inCollectionNames;
    useWildCards = inuseWildCards;
    }
    public string queryExpression;
    public string InstanceName;
    public string CollectionNames;
    public bool useWildCards;
    }

    In the SearchResults.cs class
    ======================
    public void PerformSearch(object sender, SearchActivatedEventArgs e)
    {
    ....
    }

    Enjoy...George
    George Leithead, Jul 12, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mwschenckCRL
    Replies:
    0
    Views:
    315
    mwschenckCRL
    Oct 27, 2006
  2. M.L.
    Replies:
    1
    Views:
    79
    Tim Williams
    Jul 17, 2005
  3. M. Strobel
    Replies:
    1
    Views:
    201
    The Natural Philosopher
    Mar 5, 2013
  4. Thomas 'PointedEars' Lahn

    Re: getting perl and php to talk to each other

    Thomas 'PointedEars' Lahn, Mar 5, 2013, in forum: Perl Misc
    Replies:
    7
    Views:
    245
    Scott Johnson
    Mar 14, 2013
  5. SwissCheese
    Replies:
    2
    Views:
    277
    Thomas 'PointedEars' Lahn
    Mar 18, 2013
Loading...

Share This Page