A number of controls

G

George Leithead

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
 
G

George Leithead

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!
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top