A number of controls

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

  1. Hi all,

    Would be obliged if you could give me some advice on how to do this:

    I have a requirement that the client wants me to build a Web control
    that can be dragged and dropped from the tool box, just like any other.
    Ok so far. However, this control needs to provide a number of
    controls within it (let's say a couple text boxes, a button and a
    datagrid), and some basic validation.

    Firstly, how do I go about this. Is it a composite control, or
    something else? Some code direction would be helpful.

    Secondly, upon postback I need to re-populate the controls and also
    populate the datagrid with the esults from a Web service.

    Lastly, I would really like to provide them with as much flexibility in
    the overall control, so that they can position the composite controls
    them selves anywhere within the page. Would it be better providing a
    number of different controls, then somehow making them work together
    (some advice and code direction would be benefitial, especially in C#
    for ASP.NET 2.0).

    Ideas anyone?

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

  2. Ok, so I have made some progress. Thought that I would share it...

    The solution is to create a custom WebControl in Visual Studio 2000 and
    ASP.NET 2.0.

    I do have another question however. If I create another custom
    control, how do I make an event from this control (the button Click)
    trigger an event in another control (preferably without knowing the ID
    of the controls)??? Kind of like a listener???

    The code I have so far is below:
    ======================

    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace MyWebControlLibrary
    {

    [DefaultProperty("Text")]
    [ToolboxData("<{0}:MyBasicSearch
    runat=server></{0}:MyBasicSearch>")]
    public class MyBasicSearch : WebControl, INamingContainer
    {
    private string _Collections;
    private Button _SearchButton;
    private Label _SearchLabel;
    private TextBox _SearchTextBox;

    // The following properties are delegated to child controls.
    #region Child Controls

    [Category("Collections"),
    Description("The Coveo Collection to allow searching
    against.")]
    public string Collections
    {
    get
    {
    EnsureChildControls(); // Expose properties of child
    controls as top-level properties. This is useful when you want to allow
    the page developer to access the properties of a child control.
    return _Collections;
    }
    set
    {
    EnsureChildControls(); // Expose properties of child
    controls as top-level properties. This is useful when you want to allow
    the page developer to access the properties of a child control.
    _Collections = value;
    }
    }

    [Category("Appearance"),
    DefaultValue("Search For: "),
    Localizable(true),
    Description("Text for the Search for label.")]
    public string SearchLabelText
    {
    get
    {
    EnsureChildControls(); // Expose properties of child
    controls as top-level properties. This is useful when you want to allow
    the page developer to access the properties of a child control.
    return _SearchLabel.Text;
    }
    set
    {
    EnsureChildControls(); // Expose properties of child
    controls as top-level properties. This is useful when you want to allow
    the page developer to access the properties of a child control.
    _SearchLabel.Text = value;
    }
    }

    [Category("Appearance"),
    DefaultValue("Search"),
    Localizable(true),
    Description("Text for the Search button.")]
    public string SearchButtonText
    {
    get
    {
    EnsureChildControls(); // Expose properties of child
    controls as top-level properties. This is useful when you want to allow
    the page developer to access the properties of a child control.
    return _SearchButton.Text;
    }
    set
    {
    EnsureChildControls(); // Expose properties of child
    controls as top-level properties. This is useful when you want to allow
    the page developer to access the properties of a child control.
    _SearchButton.Text = value;
    }
    }
    #endregion

    protected override void CreateChildControls()
    {
    Controls.Clear();

    _SearchLabel = new Label(); // A label for the search text
    input box
    /// A search text box
    _SearchTextBox = new TextBox();
    _SearchButton = new Button(); // A button
    _SearchButton.Click += new EventHandler(_button_Click);

    Controls.Add(_SearchLabel); // Controls[0]
    Controls.Add(_SearchTextBox); // Controls[1]
    Controls.Add(_SearchButton); // Controls[2]
    }

    // Handles the Click event of the Search Button
    private void _button_Click(object source, EventArgs e)
    {
    /// TODO: Implement the event raise to page level so that
    when the search button is hit, we execute the search, and display the
    results!
    }
    }
    }


    George Leithead wrote:
    > Hi all,
    >
    > Would be obliged if you could give me some advice on how to do this:
    >
    > I have a requirement that the client wants me to build a Web control
    > that can be dragged and dropped from the tool box, just like any other.
    > Ok so far. However, this control needs to provide a number of
    > controls within it (let's say a couple text boxes, a button and a
    > datagrid), and some basic validation.
    >
    > Firstly, how do I go about this. Is it a composite control, or
    > something else? Some code direction would be helpful.
    >
    > Secondly, upon postback I need to re-populate the controls and also
    > populate the datagrid with the esults from a Web service.
    >
    > Lastly, I would really like to provide them with as much flexibility in
    > the overall control, so that they can position the composite controls
    > them selves anywhere within the page. Would it be better providing a
    > number of different controls, then somehow making them work together
    > (some advice and code direction would be benefitial, especially in C#
    > for ASP.NET 2.0).
    >
    > Ideas anyone?
    >
    > George Leithead
    George Leithead, Jun 19, 2006
    #2
    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. makok
    Replies:
    1
    Views:
    6,751
    Anders Hellerup Madsen
    Feb 23, 2004
  2. hari
    Replies:
    6
    Views:
    6,910
    hamilton
    May 2, 2004
  3. mayur
    Replies:
    2
    Views:
    1,003
    Natty Gur
    Jul 2, 2004
  4. Replies:
    5
    Views:
    511
    Pete Becker
    May 21, 2005
  5. Nathan Sokalski
    Replies:
    4
    Views:
    1,135
    Muhammad Naveed Yaseen
    Sep 5, 2007
Loading...

Share This Page