Attaching to event in container object

  • Thread starter Cowboy \(Gregory A. Beamer\)
  • Start date
C

Cowboy \(Gregory A. Beamer\)

I have a user control that has a group of links. It is included on every
page of a web application. Some of the pages are forms, and the requirements
state "if any of the data has changed, you must ask the user if they want to
save the changes." I can solve this by dynamically setting a group of
LinkButton controls and adding a common event handler in the control.

On non-form pages, I can redirect the person to the linked page without
doing anything. On form pages, I have to check and save the data if the user
desires. I can code this in the control, but it means I have to check every
time a person clicks on the LinkButton(s).

What I would like to experiment with is setting up the lb_Click() event
handler in the Page and link the Control to the event in the page. This will
allow me to simply redirect on non-form pages and handle the data on form
pages. The code is simplified over the control embedded event handler, as I
do not have to check the type of page.

I can, of course, kludge up the works a bit by setting a property on the
control (which actually may be a better solution), but I would still like to
play with the container (page) of a control.

The question is whether or not it can easily be done.

this.Page does not seem to return the containing page
this.Parent returns the base class (as expected)

Just curious as to this.? gives me the object that the control is sitting on
(ie, the container).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
A

Alvin Bruney

Probably a better approach would be to subscribe to the click event handler
of the button. This way, you get notified whenever the event fires. New
pages would just have to hook into the delegate and they would be notified
automatically, ie their methods would fire asynchronously releasing you from
much of the coding associated with monitoring for the event on all the pages
etc.

If you want the containing page you'd have to look for the owner or
container of the page which isn't necessarily the parent

regards
 
C

Cowboy \(Gregory A. Beamer\)

I have already set up with the event in the control, which is fine, but I am
just geeky enough to try something a bit out of the box. ;-0

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top