How do you expose the event of a child server control from within a custom control?

I am trying to create a custom control that has a server control (dropdownlist) as a child.  I need to be able to expose the selectedindexchanged event from the dropdownlist at the page level.  How do you do this?  Here is a quick abbreviated example I wrote to show what I am trying to do:

 My Custom Control

1    Public Class MyCustomControl
2        Inherits Control
3        ' Variables
4        Protected WithEvents ddlServerControl As New DropDownList
5        ' Methods
6        Private Sub MyCustomControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
7            Me.ddlServerControl.AutoPostBack = True
8            Me.Controls.Add(ddlServerControl)
9        End Sub
10       Private Sub ddlServerControl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlServerControl.SelectedIndexChanged
11           Page.Response.Redirect("", True)
12       End Sub
13   End Class

 My Page File

1    <%@ Page Language="VB" %>
2    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
3    <script runat="server">
4        ' What code do I put here to capture the selected index change of the drop down list control that is a child of the custom control?
5    </script>
6    <html xmlns="">
7    <head runat="server">
8        <title>Untitled Page</title>
9    </head>
10   <body>
11       <form id="form1" runat="server">
12           <div>
13               <MoGiZ:MyCustomControl ID="mccTest" runat="server" />
14           </div>
15       </form>
16   </body>
17   </html>

I know you have to do something around adding/registering event handlers, but I have read many examples and am still lost.  Any help would be very appreciated.  Thank you!


Mr. Mogiz
11/13/2007 9:29:53 PM 93655 articles. 6 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 0

Okay... I played around with things a little bit, and figured out the reason the examples I found in other posts weren't working is because I wasn't doing the load event everytime, so my child controls were missing (thus no events firing).  Got it now.


Mr. Mogiz
11/13/2007 10:41:45 PM

Similar Artilces:

How do you expose an event from a server control within an user control on an web form?
I have a calendar inside of an user control Simple.ascx The user control is sitting on my web form Simple.aspx. How do I access the VisibleMonthChanged event from my web form Simple.aspx? Is it possible? Yes Create Event in usercontrol which fires on page when VisibleMonthChanged event fires on usercontrol. Jigar Desai-----------------------Do not forget to "Mark as Answer" on the post that helped you. Ok, I created the event Public Event MonthChanged() in Simple.ascx.vb. Then I add the follow to Simple.aspx.vb Private Sub Simple_MonthChanged() Si...

Web Custom Control within a Web Custom Control
I was wondering if this can be done and how. I've created a simple custom control that displays a header which is my first custom control. So I'm just a baby when it comes to this.. Within the header I currently have a property for breadcrumbs which is a string. What I would like to do is have the breadcrumb property  be a Link Button List. I did find a custom control of a Link Button List which is exactly what I wanted. My question is how can/do  I include this into my custom control? Can it done? How? Please help? I'm at a lose here.   Susan You should be able to do ...

Custom web control and child control events
I generate a LinkButtons in a CreateChildControls() method of a custom web control and I want to catch click events of these LinkButtons in this custom web control class (in some method). Is it possible? Martin public class ExampleCompositeControl { public override ControlCollection Controls { get { EnsureChildControls(); return base.Controls; } } protected override void CreateChildControls() { this.Controls.Clear(); myLink = new LinkButton(); myLink.Click += new EventHandler( myLink_Click ); this.Controls.Add( myLink ); ...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer sites and/or SharePoint sites why don't you just create Web Par...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Server Web User Control or Web Custom Control
Ok, I made a DataGrid I like, stuck it in a Web Control Lib, and then to my toolbar. Now I want to take my nice little control and add it to a greater control, maybe place some buttons around it etc. I could always inherit from it in a new custom control and dynamically add the buttons, but I thought about using a Web User Control. I thought I could easily create a Web User Control, drop on my grid and the buttons on a form, and expose some properties and events, but once I got into it, I got a feeling that this isn't what a Web User Control is for. When designing a control li...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Exposing controls within a Web User Control
HiI've just started using web user controls, and I'd like to know if it's possible to change elements dynamically from within other pages?In other words, I've created a simple Web User Control and added just a link.I've added the User Control to a new page, and from the code behind, I'd like to 'call' the link from within the web user control and change its class property.Is this possible? If so, could someone please show me? I'm using C#. Many thanksRichard U need to use find control.. HyperLink h = (HyperLink)(yourUserControl.Findcontrol(...

Custom Control wont expose child controls
Hi,I just wrote a custom control that wraps a few other controls, and makes it able to expand/minimize.However, I made a simple property that is used as a template to put the other controls in. However I can't directly access these controls from my page object. Is it possible to access these controls from the Page directly? I don't want to use FindControl on the custom control.Any thoughts?Thanks in advance I did the same thing....a collapseable panel using templates.  In the end, I have to use FindControl and it is quite annoying.  If anyone figures this out, please let us know!...

Handling events from controls within custom controls
Hi, I have created a custom control that behaves similar to a placeholder control. In the Render control I simply render the sub-controls that have been programiatically added, like this: protected override void Render(HtmlTextWriter writer){    foreach (Control control in Controls)    {        control.RenderControl(writer);    } ... This is fine. I can programatically add a button with an event handler to this control in the code behind for my ASPX page, and it works with no problem. However, if I add a...

Add .Net Control to Web Custom Control
 I want to add .NET Control (like: TextBox, Button...) to Web Custom Control.How i can do it? Alphavn That's called a composite control -- "Mark As Answer" if my reply helped you -- Hello Guys What gunteman said, that is one approach and in most cases the right one.But its also possible to add child controls to a Control thats inherit from WebControl itself. Be sure to implement INamingContainer to that inherited Control too, thats the important point of that approach.--Microsoft MVP - Visual Developer ASP / ASP.NET-

handling events for controls in custom server control
Hi,     I am having a problem in using server controls in ASP.Net, with C#.  I am trying to create a server control which contains 2 other server controls that I created (Called MyImageButton).  MyImageButton extends the standard ImageButton with some other properties & methods that I needed.  It therefore also has the 'OnClick' event.  From the original server control, I would like to handle the Click event for these 2 image buttons in the same server control.  Basically, this server control will show 2 images, ascending and descendin...

Web resources about - How do you expose the event of a child server control from within a custom control? -

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Home lost after out-of-control grassfire at Edgecombe in central Victoria
One home is lost after a fast-moving grassfire sweeps through Edgecombe in central Victoria..

Contextual and Granular Notification Controls
... written a lot about notifications, at one point calling the notifications screen “my home screen.” But I don’t like how we are forced to control ...

ESI cost control and networks
There is an interesting discussion thread on Twitter about how the way Medicare for All saves money is by significantly reducing provider, device, ...

US Democratic debate: Candidates spar on gun control
Candidates in the Democratic race for the White House hold their liveliest TV debate yet, clashing over gun control and healthcare among other ...

Doro PDF printer adds color conversion, page rotation controls
Lightweight virtual PDF printer Doro has been updated with new color conversion and page rotation settings. If the default "UseDeviceIndependentColor" ...

While No One Was Watching, Obama Took Control of the Courts
... and President Obama’s legacy.” It didn’t favor conservatives but there was a dramatic shift to the far left. The appellate is under the control ...

Sanders Backs Gun Control Legislation Ahead of Democratic Debate
Hillary Clinton's campaign calls her rival's move a "debate-eve conversion."

Myo armbands used to control prosthetic arm
The Myo gesture-controlled armband has been used to create a robotic prosthetic arm that can be controlled by the user's muscles.

Guns Control: A Complicated Love Story
Guns! 'Merica! That second amendment gives people lots of permission to go shoot 'em up! Right? Susie thinks it's all great but for some people ...

Resources last updated: 1/19/2016 11:37:42 PM