Professional Web Applications Themes

Capture an Event in a composite control From control on a page - ASP.NET Building Controls

In the most simple terms assume we have a Composite WebServer control This Composite Control (CC) is just a "label" private Label _lblCommissionType; protected override void CreateChildControls() { Controls.Clear(); this._lblCommissionType = new Label(); this._lblCommissionType.Text ="Premium: "; this.Controls.Add(_lblCommissionType); } protected override void Render(HtmlTextWriter writer) { EnsureChildControls(); _lblCommissionType.RenderControl(writer); } I want to add an Event Handler to this CC which captures the event SelectedIndexChanged in a standard DropDownList drawn beside it on the page. i.e. DropDownList1 When the Event is captured I want to change the text of the (CC) label Please Help -- just ask for more details if required C# ...

  1. #1

    Default Capture an Event in a composite control From control on a page

    In the most simple terms assume we have a Composite WebServer control

    This Composite Control (CC) is just a "label"

    private Label _lblCommissionType;

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

    this._lblCommissionType = new Label();
    this._lblCommissionType.Text ="Premium: ";
    this.Controls.Add(_lblCommissionType);

    }

    protected override void Render(HtmlTextWriter writer)
    {
    EnsureChildControls();
    _lblCommissionType.RenderControl(writer);

    }

    I want to add an Event Handler to this CC which captures the event
    SelectedIndexChanged in a standard DropDownList drawn beside it on the
    page. i.e.
    DropDownList1

    When the Event is captured I want to change the text of the (CC) label

    Please Help -- just ask for more details if required

    C#
    VS.NET 2003
    ..NET v1.1

    gdick@kerrhenderson.com Guest

  2. #2

    Default Re: Capture an Event in a composite control From control on a page

    Hi,

    if DropDownList is not inside the composite control, it doesn't make sense
    for it to wire for the DropDownList's SelectedIndexChanged, since that would
    make it always dependant of DDL on page. Instead you would expose Text
    property from this composite control. Then handle DropDownList's
    selectedIndexChanged on page and set the Text there. Unless your composite
    control tries to address the need to have them together, of course.

    However, it might make more sense, if you have the DropDownList in this very
    same composite control, when accessing it inside the control would be very
    easy. Another way is to define some "AssociatedDropDownListID" property in
    the composite control, to which ID of the DropDownList is given. Composite
    control could run Page.FindControl etc with the ID to get reference to the
    DropDownList and use it, that's another way.


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    [url]http://blogs.aspadvice.com/joteke[/url]




    <gkerrhenderson.com> wrote in message
    news:1155214999.211468.21464075g2000cwc.googlegro ups.com...
    > In the most simple terms assume we have a Composite WebServer control
    >
    > This Composite Control (CC) is just a "label"
    >
    > private Label _lblCommissionType;
    >
    > protected override void CreateChildControls()
    > {
    > Controls.Clear();
    >
    > this._lblCommissionType = new Label();
    > this._lblCommissionType.Text ="Premium: ";
    > this.Controls.Add(_lblCommissionType);
    >
    > }
    >
    > protected override void Render(HtmlTextWriter writer)
    > {
    > EnsureChildControls();
    > _lblCommissionType.RenderControl(writer);
    >
    > }
    >
    > I want to add an Event Handler to this CC which captures the event
    > SelectedIndexChanged in a standard DropDownList drawn beside it on the
    > page. i.e.
    > DropDownList1
    >
    > When the Event is captured I want to change the text of the (CC) label
    >
    > Please Help -- just ask for more details if required
    >
    > C#
    > VS.NET 2003
    > .NET v1.1
    >

    Teemu Keiski Guest

Similar Threads

  1. composite control does not fire event
    By Patrick in forum ASP.NET Building Controls
    Replies: 2
    Last Post: July 19th, 06:35 AM
  2. Not Able to trigger event in Composite Control
    By King Kong in forum ASP.NET Building Controls
    Replies: 2
    Last Post: December 17th, 10:59 PM
  3. Composite Control - Event not firing in child control
    By Chris Simmons in forum ASP.NET Building Controls
    Replies: 3
    Last Post: October 28th, 09:45 PM
  4. Replies: 2
    Last Post: July 22nd, 10:58 PM
  5. Replies: 2
    Last Post: July 2nd, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139