Attaching to event in container object

Discussion in 'ASP .Net' started by Cowboy \(Gregory A. Beamer\), Oct 24, 2003.

  1. 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!
    **********************************************************************
    Cowboy \(Gregory A. Beamer\), Oct 24, 2003
    #1
    1. Advertising

  2. Cowboy \(Gregory A. Beamer\)

    Alvin Bruney Guest

    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

    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    "Cowboy (Gregory A. Beamer)" <> wrote in
    message news:...
    > 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!
    > **********************************************************************
    >
    >
    Alvin Bruney, Oct 25, 2003
    #2
    1. Advertising

  3. 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!
    **********************************************************************
    "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com> wrote in
    message news:%...
    > 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
    >
    > --
    >
    >
    > -----------
    > Got TidBits?
    > Get it here: www.networkip.net/tidbits
    > "Cowboy (Gregory A. Beamer)" <> wrote in
    > message news:...
    > > 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!
    > > **********************************************************************
    > >
    > >

    >
    >
    Cowboy \(Gregory A. Beamer\), Oct 28, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?V2ViTWF0cml4?=
    Replies:
    6
    Views:
    392
    =?Utf-8?B?V2ViTWF0cml4?=
    Dec 7, 2004
  2. Per
    Replies:
    1
    Views:
    357
    Howard
    Apr 18, 2005
  3. =?Utf-8?B?RGF2ZQ==?=

    attaching an event to ServerValidate

    =?Utf-8?B?RGF2ZQ==?=, May 15, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    401
    =?Utf-8?B?S2VpdGg=?=
    May 15, 2007
  4. hharry

    VS 2005..Attaching event handlers

    hharry, May 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    296
    bruce barker
    May 21, 2007
  5. Replies:
    5
    Views:
    164
    Thomas 'PointedEars' Lahn
    Jun 6, 2005
Loading...

Share This Page