Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > A number of controls

Reply
Thread Tools

A number of controls

 
 
George Leithead
Guest
Posts: n/a
 
      06-16-2006
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

 
Reply With Quote
 
 
 
 
George Leithead
Guest
Posts: n/a
 
      06-19-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot Nathan Sokalski ASP .Net 4 09-05-2007 03:27 AM
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM
real number to 16 bit signed number hari VHDL 6 05-02-2004 04:10 PM
IE 6.0 sockets number (TCP/IP channels number) for the same Site ??? taras ASP .Net 1 04-17-2004 04:51 AM
Convert decimal number in binary number makok VHDL 1 02-23-2004 06:04 PM



Advertisments