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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:32:25+00:00 2026-05-28T15:32:25+00:00

I have two user controls on the same page. One contains a ListView that

  • 0

I have two user controls on the same page. One contains a ListView that displays navigation links, the second user control should be updated when user clicks on the buttonlink in the ListView. How can I do this?

  • 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-28T15:32:25+00:00Added an answer on May 28, 2026 at 3:32 pm
    1. UserControl A should handle the button-click and raise a custom event declared in the UserControl
    2. The page handles this event and calls a public method of UserControl B that updates it’s content

    You could pass necessary informations from UserControl A to page via EventArgs(or pass the UserControl itself as argument and use it’s public properties).

    The page then passes the arguments to UserControl B via method parameter or by changing it’s public properties before calling the Update-Method.

    • http://msdn.microsoft.com/en-us/library/fb3w5b53.aspx
    • http://chiragrdarji.blogspot.com/2007/08/raise-event-from-user-control-to-main.html

    Here is the sample code you’ve requested.
    Sorry for the meaningless naming but you haven’t told what’s this all about. You should use readable variables,properties,method and event-names instead.

    Reduced UserControl A with a ListView:

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="UsercontrolA.ascx.vb" Inherits="WebApplication1.UserControlA" %>
    <asp:ListView ID="ListView1" runat="server">
        <ItemTemplate>
            <asp:LinkButton ID="LinkButton1" 
            CommandName="LinkClick" 
            CommandArgument='<%#Eval("ID") %>' 
            runat="server" 
            Text='<%#Eval("Text") %>'></asp:LinkButton>
        </ItemTemplate>
    </asp:ListView>
    

    Removed the ListView databinding from codebehind because that doesn’t matter. The important part is handling the ListView’s ItemCommand and raising the custom event:

    Public Event LinkClicked(sender As UserControlA, id As Int32)
    
    Private Sub LV_ItemCommand(sender As Object, e As ListViewCommandEventArgs) Handles ListView1.ItemCommand
        If e.CommandName = "LinkClick" Then
            Dim id = CType(e.CommandArgument, Int32)
            ' This is the best way for UC's to commmunicate with the page: '
            RaiseEvent LinkClicked(Me, id)
        End If
    End Sub
    

    Simple UserControl B with nothing more than a Label(ascx):

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="UserControlB.ascx.vb" Inherits="WebApplication1.UserControlB" %>
    <asp:Label ID="Label1" runat="server"></asp:Label>
    

    With an Update-Method in codebehind:

    Public Sub Update(showID As Int32)
        Me.Label1.Text = String.Format("Link {0} clicked", showID.ToString)
    End Sub
    

    Finally, here is the Page(aspx)

    <uc1:UsercontrolA ID="UC_A" runat="server" />
    <br />
    <uc2:UserControlB ID="UC_B" runat="server" />
    

    It controls both UserControls. It handles the event from UserControl A and calls the Update-Method that UserControl B provides:

    Private Sub LinkClicked(sender As UserControlA, id As Integer) Handles UC_A.LinkClicked
        Me.UC_B.Update(id)
    End Sub
    

    The advantage of this event-approach is that UserControls stay being reusable. You can use UserControl A in other pages as well even when they don’t handle this event. It’s part of the controller to decide what is needed and what should be done.

    UserControls as a rule should not depend on specific controllers, otherwise they are hard-linked and not reusable. That would be also a good source for nasty erros. A UserControl might be a controller for other nested (User-)Controls but not for the page itself.

    Communication Summary:

    • Page -> UserControl -> public properties and methods
    • UserControl -> Page -> Events
    • UserControl -> UserControl -> the controller-UserControl adopts the page-role(see above)
    • 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 page with two instances of the same Web User Control
I have a user control in a master page with two drop down lists.
Have a page that adds controls dynamically. Control state is being retrieved from database
I have two user controls that need to add a class atribute to the
Is it possible to have two controls on one page side-by-side in Silverlight? It
How we can implement Two recaptcha user control on the same page. Problem :
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have two models -- User and Entry -- that are related through a
I have two panels that i wish to display to the user. I decided
I have two classes that my pages and controls inherit from. These two classes

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.