Problem: Custom control receives postback events for other controls

Discussion in 'ASP .Net' started by Lamont Adams, Sep 9, 2004.

  1. Lamont Adams

    Lamont Adams Guest

    Hi all,

    I've created numerous custom controls of varying complexity, but I've been
    on this problem for a day and a half, and I can't figure this mystery out. I
    hope one of you kind folks can point out the really obvious and stupid thing
    I'm overlooking here. :)

    I have a custom control that provides a tasklist similar to what you get in
    certain parts of Office. On the client it consists of a bunch of nested,
    named and id'ed divs with onclick event handlers wired to call __doPostBack
    with the control's server-side ID and a task name and task Id as arguments
    (example for a control named Tasks: __doPostBack("Tasks",
    "CreateNewProject;task1")). The server control implements
    IPostbackEventHandler to raise a TaskClick event into the hosting page. This
    control's content is generated from an XSLT transform of a page-supplied XML
    file that's written directly to the response stream in RenderContents. It
    doesn't contain any child controls, or do anything else fancy beyond storing
    a handful of string properties in its viewstate.

    Here's the thing: This control's RaisePostbackEvent method is being called
    on each and every submit/postback of the form. The way I understand the
    postback mechanism, this shouldn't be happening. I'm fuzzy on submit
    buttons, but for controls that invoke __doPostBack on the client, the
    framework figures out which control to raise the event on from the
    __EVENTTARGET form field, and looks for an IPostbackEventHandler implementer
    that has the right ID, right? Well, Request.Form("__EVENTTARGET") always has
    the correct control's ID in it, not the taskview control's, but the taskview
    gets the event every time anyway.

    If I put a button control on the same form as the tasklist control, and wire
    an event handler in the page's codebehind, the button's click event never
    fires. If I put a label control on the page and wire a click event handler,
    it never fires. If I put one of my other custom controls on the page and
    wire an event handler for it, the handler never fires. If I put a breakpoint
    in the tasklist control's RaisePostBackEvent method, I see why: tasklist's
    RaisePostBackEvent method is being called for any postback on the page
    hosting the control.

    If I remove the taskview control from the page and recompile then all my
    event handlers fire as expected. So it has to have something to do with that
    control, but I've been over and over it and can't find a problem: it's
    really a simple control. I'm out of ideas... anyone else have any?

    Thanks in advance!
    Lamont Adams, Sep 9, 2004
    #1
    1. Advertising

  2. Lamont Adams

    Lamont Adams Guest

    Nobody has any ideas? At least confirm for me that this shouldn't be
    happening... anyone?

    "Lamont Adams" <lamontadams1atyahoo.remove.dotcom> wrote in message
    news:...
    > Hi all,
    >
    > I've created numerous custom controls of varying complexity, but I've been
    > on this problem for a day and a half, and I can't figure this mystery out.

    I
    > hope one of you kind folks can point out the really obvious and stupid

    thing
    > I'm overlooking here. :)
    >
    > I have a custom control that provides a tasklist similar to what you get

    in
    > certain parts of Office. On the client it consists of a bunch of nested,
    > named and id'ed divs with onclick event handlers wired to call

    __doPostBack
    > with the control's server-side ID and a task name and task Id as arguments
    > (example for a control named Tasks: __doPostBack("Tasks",
    > "CreateNewProject;task1")). The server control implements
    > IPostbackEventHandler to raise a TaskClick event into the hosting page.

    This
    > control's content is generated from an XSLT transform of a page-supplied

    XML
    > file that's written directly to the response stream in RenderContents. It
    > doesn't contain any child controls, or do anything else fancy beyond

    storing
    > a handful of string properties in its viewstate.
    >
    > Here's the thing: This control's RaisePostbackEvent method is being called
    > on each and every submit/postback of the form. The way I understand the
    > postback mechanism, this shouldn't be happening. I'm fuzzy on submit
    > buttons, but for controls that invoke __doPostBack on the client, the
    > framework figures out which control to raise the event on from the
    > __EVENTTARGET form field, and looks for an IPostbackEventHandler

    implementer
    > that has the right ID, right? Well, Request.Form("__EVENTTARGET") always

    has
    > the correct control's ID in it, not the taskview control's, but the

    taskview
    > gets the event every time anyway.
    >
    > If I put a button control on the same form as the tasklist control, and

    wire
    > an event handler in the page's codebehind, the button's click event never
    > fires. If I put a label control on the page and wire a click event

    handler,
    > it never fires. If I put one of my other custom controls on the page and
    > wire an event handler for it, the handler never fires. If I put a

    breakpoint
    > in the tasklist control's RaisePostBackEvent method, I see why: tasklist's
    > RaisePostBackEvent method is being called for any postback on the page
    > hosting the control.
    >
    > If I remove the taskview control from the page and recompile then all my
    > event handlers fire as expected. So it has to have something to do with

    that
    > control, but I've been over and over it and can't find a problem: it's
    > really a simple control. I'm out of ideas... anyone else have any?
    >
    > Thanks in advance!
    >
    >
    >
    Lamont Adams, Sep 10, 2004
    #2
    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. newbye
    Replies:
    0
    Views:
    573
    newbye
    Jul 6, 2006
  2. Replies:
    0
    Views:
    1,318
  3. Markus Dehmann
    Replies:
    4
    Views:
    254
    Puppet_Sock
    Jan 25, 2008
  4. Wael_Bakr

    stop postback in postback events for server controls ??

    Wael_Bakr, Nov 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    488
    Wael_Bakr
    Nov 30, 2005
  5. Perry Smith

    Pure Ruby App that receives events

    Perry Smith, Aug 10, 2008, in forum: Ruby
    Replies:
    3
    Views:
    131
    John Joyce
    Aug 11, 2008
Loading...

Share This Page