public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

Capture button’s click event of user control in the page.

Posted by Virendra Dugar on February 22, 2009


Yesterday one of my colleagues was facing a problem with button placed in user control. He wanted to capture button’s click placed in user control inside the page that holds the user control.

I made a sample application for him. I thought I should share with you also.

Download Sample Code.

This is my user control (.ascx) file. As you can see I have placed a button and onclick event is also defined. (See image.)

User Control

If you want to extend the button click placed in the user control to the page, then declare an Event handler and on the click of the button just make a call to the declared event handler.  This will work as a property for any web page. See below image.

User Control

Place the control in your .aspx page. In the Page_Load event of your page, assign a new event handler to the User control’s event handler property. And, now use the newly declared event handler.

Web Page

So, now when button (which is placed in user control) is clicked, event handler declared in the page will be used to handle the click event.



4 Responses to “Capture button’s click event of user control in the page.”

  1. និមល said

    Demo1.ButtonClickDemo += new EventHandler(Demo1_ButtonClickDemo);

    Error Demo1 not define

  2. Nimol said

    Yes,it’s work now. It’s really helpful topic.
    Thanks you so much.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: