Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4003278
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:07:59+00:00 2026-05-20T08:07:59+00:00

ASP.Net web forms, .NET 2.0 I have a dilemma. I have an aspx page

  • 0

ASP.Net web forms, .NET 2.0

I have a dilemma. I have an aspx page that has a custom control:

<def:CustomControl ID="customID" runat="server" />

The custom control can be added multiple times to the ASPX page if certain criteria is met:

<asp:Repeater runat="server" ID="options" OnItemDataBound="options_OnItemDataBound">
    <HeaderTemplate>
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
    </HeaderTemplate>
    <ItemTemplate>
                <td>
                    <span>
                        <asp:Label runat="server" ID="optionName">
                        </asp:Label>
                        <asp:DropDownList runat="server" ID="optionValues" CssClass="PartOption" >
                        </asp:DropDownList>
                    </span>
                </td>
    </ItemTemplate>
    <FooterTemplate>
            </tr>
        </table>
    </FooterTemplate>
</asp:Repeater>

In the code behind of the aspx page, I wanted to append a event (OnSelectedItemChange) to the dropdown control that isn’t actually on the ASPX page (yet). However, when I try to do something like the following in the code behind:

foreach(Control eachControl in customID.Controls) {
    if (eachControl.HasControls) {
        Control DdControl = eachControl.FindControl("optionValues");  //always null

        if (DdControl != null && DdControl is typeOf(DropDownList)) {
            DdControl = DdControl as DropDownlist;  //I might have the syntax wrong
                                                    //here, but you get the point.

             //add event to control.
        }
    }
}

But All that eachControl has is a repeater, and it shows its childcontrol count as 0. So when it get to the FindControl method, it always returns null.

QUESTION
So what I am trying to do is add an event (OnSelectedItemChange) to the dropdownlist control inside the repeater (which is a custom control that gets added to the page if criteria is met). When a selection is made in the drop down, I want it to trigger the Event method.

How can I either:

A) Find a way to add the event if the dropdownlist control exists on the page?

OR

B) A way to be able to call a method in the code behind and pass the selections from all the drop down lists (since the custom control could be added more than once creating multiple drop downs?

NOTE I don’t have the code in front of me, so if I have something syntactically incorrect, please overlook. I also know that ID’s are unique, so this is also assumed to be a problem with my logic. When it renders these, the ID’s might be mangled by the asp name convention which I would assume I have to find a way around.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:08:00+00:00Added an answer on May 20, 2026 at 8:08 am

    If you create that event on the custom control, you won’t need to check if it exists on the page or not. If it does, it will definately trigger the event. Or am I missing something here?


    EDIT:

    What you’ll have to do is declare a public event on your control, then when the SelectedIndexChanged Event fired, you’d fire that event, and receive it on the page.

    So on your control you’d have:

    public delegate void MyIndexChangedDelegate(string value);
    public event MyIndexChangedDelegate MyEvent;
    
    protected void myDropDown_SelectedIndexChanged(object sender, EventArgs e)
    {
        MyEvent(myDropDown.SelectedValue); // Or whatever you want to work with.
    }
    

    Then on your page, on your control declaration you’d have:

    <usc:control1 runat="server" OnMyEvent="EventReceiver" />
    

    And on the code behind:

    protected void EventReceiver(string value)
    {
        // Do what you have to do with the selected value, which is our local variable 'value'
        ClientScript.RegisterStartupScript(typeof(Page), "Alert", string.Format("<script language='JavaScript'>alert('User selected value {0} on my DropDown!');</script>"), value);
    }
    

    That should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET Web Forms web site. It has a page inside of
I have a page in asp.net (web forms) that up until now only had
I have a ASP.NET Web Forms page that does a good amount of processing
I have an asp.net web page created with web forms. It has a number
I have a asp.net web forms app that uses System.Web.Caching.Cache to cache xml data
I have an ASP.NET 4 Web Forms app that is using URL Routing. I
I have an ASP.NET web application that is using forms authentication. Everything is configured
Using web forms I know that you can only have one ASP.NET form on
I have a windows forms client that consumes an ASP.net web service. It's my
I have a website that uses basic ASP.Net forms authentication. In the web.config file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.