Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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

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
SamJolly
Asked:
SamJolly
  • 4
  • 3
2 Solutions
 
xav056Commented:
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
 
SamJollyAuthor Commented:
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
 
xav056Commented:
yes,
how about you expose a public methods that you can  call from the page_init
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
informaniacCommented:
Did u take a look @delegates. I'm not sure of this, coz the other way arnd works using delegates.
0
 
SamJollyAuthor Commented:
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
 
SamJollyAuthor Commented:
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
 
xav056Commented:
I think the control  btnNext.ClientId will return ctl00$MainPanelContent$btnNext
0
 
SamJollyAuthor Commented:
thks. Apologies for the delay in closing
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now