Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

In ASP.NET2, How do I capture a button click event of the parent page which contains my user control.

Posted on 2011-02-21
8
Medium Priority
?
317 Views
Last Modified: 2012-06-27
Hi,

I have an ASP.NET2 page which contains a user control. This container page has some generic buttons on it like "Next", "Previous" etc. How do I capture when these parent buttons have been clicked in my User Control Code Behind. I need to do this since I need to invoke some final processing before the User Control disappears to be replaced by another.

A code example would be really handy.

Thanks,

Sam
0
Comment
Question by:SamJolly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 9

Accepted Solution

by:
xav056 earned 1800 total points
ID: 34948192
in the page_init
try this
Request.Form["__EVENTTARGET"]  that should give you the id of the control that caused the postbac if it is anajax control
alternatively if it is a regular asp button you do
Request.Form["TheIDOfYourButton"]  is that is not null it means that control caused the postback
0
 

Author Comment

by:SamJolly
ID: 34948256
I assume you are talking about the page_init in the container page. I would really like capture the event in the user control preferable using the "Handles" feature so that I can link an event handler in my User Control to the event that happened in the parent.

The parent event looks like this:

    Protected Sub btnPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrev.Click

In the User Control code I would like to get some code to run then have this parent code run as normal.
Something like this in the User Control:

Protected Sub btnPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Parent.btnPrev.Click
..... Do UserControl Final Save code
 ....Now run normal Parent.btnPrev.Click code.

Thoughts???

Thanks,

Sam


0
 
LVL 9

Expert Comment

by:xav056
ID: 34948461
yes,
how about you expose a public methods that you can  call from the page_init
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 200 total points
ID: 34949013
Did u take a look @delegates. I'm not sure of this, coz the other way arnd works using delegates.
0
 

Author Comment

by:SamJolly
ID: 34950314
Thanks all for comments.

I have just tried using the Page_Init method, in the user control, with the following code:

 Dim ctrlname As String = Page.Request.Params.Get("__EVENTTARGET")

However "ctrlName" always returns "" when I click on the Parent's buttons.

Thoughts?

0
 

Author Comment

by:SamJolly
ID: 34950409
OK, I have managed to get something to work:

        ctrlname = Request.Form("ctl00$MainPanelContent$btnNext")

This checks the "name" attribute which returns "Next" if clicked and therefore I could use this. However it does not seem to be a very ASP.NET way of doing things. I would love to know the correct ASP.NET way of doing this. I still think there must be a correct way of trapping Parent Page events, ie parent.btnNext.clicked,  within the User Control. So what is the recommended way to do this?

Thanks,

Sam
0
 
LVL 9

Expert Comment

by:xav056
ID: 34950959
I think the control  btnNext.ClientId will return ctl00$MainPanelContent$btnNext
0
 

Author Closing Comment

by:SamJolly
ID: 35076092
thks. Apologies for the delay in closing
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question