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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:14:10+00:00 2026-05-30T09:14:10+00:00

i have an usercontrol that has a public event. when i use this user

  • 0

i have an usercontrol that has a public event. when i use this user control in my web page and set the events to event handlers in my code behind through the page markup, event of my usercontrol don’t get set and are always null even in the first page load. here is a portion of my usercontrol that has a detailsview in it which i’m trying to set the events for:

[Serializable(), PersistChildren(false)]
public partial class UserControl_UCDetailsView : System.Web.UI.UserControl
{
    //here is an event for exposing detailsview1 event to the outside code
    public event DetailsViewUpdateEventHandler OnItemUpdating;
    protected void detailsview1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        //here i want it not to be null but it is. by using break points i found out 
        //this is always null and never actually get set while i've set it in markup!
        if (this.OnItemUpdating != null)
            this.OnItemUpdating(sender, e);
    }
}

here is the portion of my usercontrol markup:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UCDetailsView.ascx.cs"
    Inherits="UserControl_UCDetailsView" %>
<asp:DetailsView ID="detailsview1" runat="server" OnItemUpdating="detailsview1_ItemUpdating">
</asp:DetailsView>

and this is how i’m setting the events in my page markup:

<UC:DetailsView ID="ucDetails" runat="server" OnItemUpdating="ucDetails_ItemUpdating">
</UC:DetailsView>

in the ucDetails_ItemUpdaing i have a real updating logic like setting the fields and etc.
so why the heck if i set the event at the page load like the following the problem is resolved? i’m i missing something? an attribute maybe?

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ucDetails.OnItemUpdating += new DetailsViewUpdateEventHandler(ucDetails_ItemUpdating);
    }
}
  • 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-30T09:14:11+00:00Added an answer on May 30, 2026 at 9:14 am

    Expose the Add and Remove as Public properties.

    Note: I’ve just seen this answer on SO

    public event DetailsViewUpdateEventHandler ItemUpdating; 
    
    public event DetailsViewUpdateEventHandler OnItemUpdating
    { 
       add { this.ItemUpdating += value;} 
       remove { this.ItemUpdating -= value;} 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control that has a few public properties, one is an
I have a web user control, that has a table with 3 columns 1)
I have a user control that has button whose click event handler contains the
I have a base user control (inherited from System.Web.UI.UserControl ) public delegate void MyEventHandler(object
I have a usercontrol that has several public properties. These properties automatically show up
I have a UserControl that has a BaseClass object as a public member. Right
I have a UserControl in my Asp.net project that has a public property. I
I have a Page that has a single instance of a UserControl that itself
Suppose I have a UserControl whose DataContext is set to an object that has
I have an ASP.NET user control that is used in another use control. The

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.