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 8547899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:22:07+00:00 2026-06-11T13:22:07+00:00

Here is the structure I have set up: <UserControl1> <ListView> <UserControl2 /> <UserControl2 />

  • 0

Here is the structure I have set up:

<UserControl1>
    <ListView>
        <UserControl2 />
        <UserControl2 />
        <UserControl2 />
        <UserControl2 />
    </ListView>
</UserControl2>

When the user clicks “Edit” on UserControl2 I want to handle that event on UserControl1. So I created an event on UserControl2, added a handler on UserControl1 on ListView DataBind ,and raised the UserControl2 event on clicking “Edit”.

But when the user clicks “Edit” the whole thing posts back and the handler is lost on UserControl1. The problem is, I can’t rebind that ListView on every postback as it’s a very heavy, time-consuming operation to re-add the handler.

So how can I get UserControl1 to see UserControl2’s event?

Things I have tried:

  1. Static/Shared Events on the Usercontrol2… bad idea on an asp.net app, evidently those static events will getting mixed up some how, they exist across different webrequests I suppose.
  2. Adding a userControl1 instance property (ParentControl1) to UserControl2… nested UserControls are not allowed in asp.net.

Thanks for your help.

  • 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-06-11T13:22:08+00:00Added an answer on June 11, 2026 at 1:22 pm

    I haven’t done web forms in awhile– but I was interested in this.

    These three files will demonstrate how you can subscribe to events with user controls.

    • Basically my UserControl1 has an event which I can subscribe to.
    • UserControl2 has a ListView which will contain instances of UserControl1. I can subscribe to the event in the instances of UserControl1 while in UserControl2.
    • Default.aspx contains an instance of UserControl2

    Clicking on any of the events in UserControl1 will fire the event– which in this case just sends the text of the button which is in UserControl1.

    The code in VB should be pretty similar.

    UserControl1

    <%@ Control Language="C#" AutoEventWireup="true" %>
    <script runat="server">
        public delegate void SillyHandler(object sender, string text);
        public event SillyHandler SomethingHappened;
    
        public string Name { get; set; }
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (SomethingHappened != null)
                SomethingHappened(this.Button1, this.Button1.Text);
        }
    </script>
    <asp:Button ID="Button1" runat="server" Text="<%#this.Name %>" onclick="Button1_Click" />
    

    UserControl2

    <%@ Control Language="C#" AutoEventWireup="true" %>
    <%@ Register src="UserControl1.ascx" tagname="UserControl1" tagprefix="uc1" %>
    <script runat="server">
        public List<string> DataSource { get; set; }
    
    
        protected void SomethingHappened(object sender, string txt)
        {
            MyLabel.Text = txt;
        }
    </script>
    <asp:ListView runat="server" ID="ListView1" DataSource="<%#DataSource %>">
        <ItemTemplate>
            <uc1:UserControl1 ID="UserControl11"  runat="server" OnSomethingHappened="SomethingHappened" Name="<%#Container.DataItem %>"/>
        </ItemTemplate>
    </asp:ListView>
    
    <asp:Label runat="server" ID="MyLabel" />
    

    Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" %>
    
    <%@ Register src="UserControl2.ascx" tagname="UserControl2" tagprefix="uc1" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.UserControl21.DataSource = new List<string> { "A", "B", "C" };
                this.UserControl21.DataBind();
            }
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    
            <uc1:UserControl2 ID="UserControl21" runat="server" />
    
        </div>
        </form>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem here that requires to design a data structure that takes
I want to have a dictionary that assigns a value to a set of
A novice R user here. So i have a data set formated like: Date
I have a set of custom user controls, of type ChartControl. I want to
For example I have a file name call A.java. Here its structure: public class
I have menu structure as show here . All item have a background img.
I have a document structure {'text': 'here is text', 'count' : 13, 'somefield': value}
I have a complex form in Ruby on Rails 2.3.5, here's the structure for
suppose you have the following structure: #include <windows.h> // BOOL is here. #include <stdio.h>
I have the following structure: <div class=parent> <div id=child1>Content here</div> <div class=child2>Content here</div> </div>

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.