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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:16:35+00:00 2026-05-16T02:16:35+00:00

I have a question about creating and managing events inside an ascx custom web

  • 0

I have a question about creating and managing events inside an ascx custom web control.

I have created a very stupid control consisting in a div containing a asp:Label control, it is a very simple structure:

<div id="mydiv" runat="server">
     <asp:Label id="mylabel" text="Text"... />
</div>

That is, very simple.
I would like to add an event: clicked. I want to let the user add this control on the page and attach handlers to this event so that when this control is clicked it is possible to do something. It might seem a strange solution, it’s like i’m trying to invent again the button control, that is: my custom button.
Well to fire the event I would like to add a javascript in my div and call a js function that calls, using ajax mechanism, a server side function.
Well how to call a server side function from here. I posted a question about how to call a server side function from a client side one and got some answers (many of them told me to use PageMethods), well it seems that pagemethod does not work, it compiles but when running and clicking on my control and executing the js (in the line PageMethods.mymethod()) here I have an error –> Java script exception: unrecognized method. It seems not finding the PageMethod.

Well, considering my objective, how can I do?
Ah, a solution like: use the click event in the label is not what I want because the click event must fire when I click in the div, consider that I might set a large padding so that a large empty space can provide a large clickable area.

Thanks in advance.

  • 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-16T02:16:36+00:00Added an answer on May 16, 2026 at 2:16 am

    Create a Event in your User Control

    E.g: –

    public event EventHandler<CustomEventArgs> Click;
    

    and a handler

    public void OnClick()
    {
    if(this.Click !=null)
    {
        //what ever else you do
        this.Click(new CustomEventArgs(...));
    }
    }
    

    Also handle the mouse click (mouseleftbuttonup) on the User Control (and fire your event from there). i.e.

    protected void OnMouseDown(...){ this.OnClick(); }
    

    From the ASP.NET page, you can register the user control event and handle it:

    MyControl.Click += new EventHandler<CustomEventArgs>(myctr_click)
    
    protected myctr_click(object sender, CustomEventArgs e){
    //do anything
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created public synonym as suggested in my other question about creating view
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have a little question about creating a table using another tables. my code:
I have a question about manually creating a .Net webservice proxy class. The WSDL
I have a simple question about creating multiple initialisers within an objective-c class. Basically
I have a question about using streams in .NET to load files from disk.
I have a question about best practices regarding how one should approach storing complex
I have a question about locking. This doesn't have to be only about record
I have a question about how to deploy WPF application into a PC without
I have a question about using os.execvp in Python. I have the following bit

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.