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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:33:04+00:00 2026-05-29T23:33:04+00:00

I am making a C# Web Application in .Net I have overridden the Panel

  • 0

I am making a C# Web Application in .Net

I have overridden the Panel control to make a div clickable. It looks like this:

public class ProjectPanel : System.Web.UI.WebControls.Panel, System.Web.UI.IPostBackEventHandler
{
    public ProjectPanel() 
    {
        CssClass = "project";
        this.Click += new EventHandler(ProjectPanel_Click);
    }

    public event EventHandler Click;

    protected virtual void OnClick(EventArgs e)
    {
        if (Click != null)
        {
            Click(this, e);
        }
    }

    public void RaisePostBackEvent(string eventArgument)
    {
        OnClick(new EventArgs());
    }

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        this.Attributes.Add("onclick", "__doPostBack('" + this.ClientID + "', '');");
        base.Render(writer);
    }
    public void ProjectPanel_Click(object sender, EventArgs e)
    {
        Label l = new Label();
        l.Text = " HIYA";
        this.Controls.Add(l);
    }
}

Now, this works fine inside a Page. However, I also have a Web User Control which looks like:

<div class="team">

<asp:Panel runat="server" ID="TheCanvas" CssClass="projects" />

</div>

Now when I add the overriden Panel to the TheCanvas panel, the click event isnt registered anymore. The postback happens, but the ProjectPanel_Click doesnt fire. Any ideas? I’m adding the panel through code.

  • 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-29T23:33:06+00:00Added an answer on May 29, 2026 at 11:33 pm

    Instead of ClientID you should use UniqueID because when in another control client ID is prefixed with parend client ID, replace onclick attribute setting with this :

    this.Attributes.Add("onclick", "__doPostBack('" + this.UniqueID + "', '');");
    

    btw. you should be aware that if you don’t have on page another control that implements IPostBackDataHandler, __doPostback javascript would not be present and you will get javascript error:

    __doPostBack is not defined

    You should implement IPostBackDataHandler and call Page.RegisterRequiresPostBack(this) inside your panel control, see details on this links:

    http://aspalliance.com/1071_Smart_ListControl_in_ASPNET_1x20.4

    http://www.timvasil.com/blog14/post/2007/10/30/Implementing-IPostBackDataHandler-once-and-for-all.aspx

    • 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 application that I am making and I am thinking
I have this existing environment: 1) ASP.NET 3.5 web application 2) forms authentication with
I have an ASP.Net Framework 4 web application making an interop call to a
I making web application for iphone user. I have HTML table structure inside asp.net
We are making a Web application for Blackberry (ASP.NET). The customer would like to
I hope this is ok asking here.. I Have been making an asp.net application
So I have an ASP.NET web site (not web application) I'm making in VS2010
I am making my first web application with ASP.NET and I am having a
I'm making a small web application in Seaside. I have a login component, and
I have been making a little toy web application in C# along the lines

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.