Identify control that caused postback

Discussion in 'ASP .Net' started by Joey G, Nov 10, 2004.

  1. Joey G

    Joey G Guest

    How do I get the name or identify the control that caused
    the page postback. I need the information during page
    init. Reason why, because I need to tell usercontrol_1
    that usercontrol_2 button was clicked and therefore need
    usercontrol_2 public properties to be passed to
    usercontrol_1 public properties in the case of the event.

    thanks
     
    Joey G, Nov 10, 2004
    #1
    1. Advertising

  2. Joey G

    Scott M. Guest

    The page load event (as well as most other controls) has a Sender as Object
    argument. Sender is the object that cause the event handler to fire.

    If you use Sender.GetType.Name, you can get the name of the type that caused
    the postback.


    "Joey G" <> wrote in message
    news:19cb01c4c764$3c95e510$...
    > How do I get the name or identify the control that caused
    > the page postback. I need the information during page
    > init. Reason why, because I need to tell usercontrol_1
    > that usercontrol_2 button was clicked and therefore need
    > usercontrol_2 public properties to be passed to
    > usercontrol_1 public properties in the case of the event.
    >
    > thanks
     
    Scott M., Nov 10, 2004
    #2
    1. Advertising

  3. Joey G

    Joey G Guest

    Thanks for the response Scott, but that is not the case. I felt the same
    way, but the object that caused the postback is only the sender of the wired
    event (i.e. usercontrol_2_button_click(byval sender as....)) and not the
    sender of the page_init or page_load.

    "Scott M." <> wrote in message
    news:...
    > The page load event (as well as most other controls) has a Sender as
    > Object argument. Sender is the object that cause the event handler to
    > fire.
    >
    > If you use Sender.GetType.Name, you can get the name of the type that
    > caused the postback.
    >
    >
    > "Joey G" <> wrote in message
    > news:19cb01c4c764$3c95e510$...
    >> How do I get the name or identify the control that caused
    >> the page postback. I need the information during page
    >> init. Reason why, because I need to tell usercontrol_1
    >> that usercontrol_2 button was clicked and therefore need
    >> usercontrol_2 public properties to be passed to
    >> usercontrol_1 public properties in the case of the event.
    >>
    >> thanks

    >
    >
     
    Joey G, Nov 10, 2004
    #3
  4. Maybe you're headed down a better path, but for communicating among user
    controls I'd instead raise events--i.e. your user controls each raise a
    different event on button click, and your other controls, page, etc. can
    listen for it if they want. This makes it much easier to orchestrate, say, in
    cases where you use the same controls on multiple pages.

    Bill

    "Joey G" wrote:

    > How do I get the name or identify the control that caused
    > the page postback. I need the information during page
    > init. Reason why, because I need to tell usercontrol_1
    > that usercontrol_2 button was clicked and therefore need
    > usercontrol_2 public properties to be passed to
    > usercontrol_1 public properties in the case of the event.
    >
    > thanks
    >
     
    =?Utf-8?B?QmlsbCBCb3Jn?=, Nov 10, 2004
    #4
  5. Hi,
    How can I know which button cause the postback event in page_load event?
    Thanks


    "Joey G" wrote:

    > Thanks for the response Scott, but that is not the case. I felt the same
    > way, but the object that caused the postback is only the sender of the wired
    > event (i.e. usercontrol_2_button_click(byval sender as....)) and not the
    > sender of the page_init or page_load.
    >
    > "Scott M." <> wrote in message
    > news:...
    > > The page load event (as well as most other controls) has a Sender as
    > > Object argument. Sender is the object that cause the event handler to
    > > fire.
    > >
    > > If you use Sender.GetType.Name, you can get the name of the type that
    > > caused the postback.
    > >
    > >
    > > "Joey G" <> wrote in message
    > > news:19cb01c4c764$3c95e510$...
    > >> How do I get the name or identify the control that caused
    > >> the page postback. I need the information during page
    > >> init. Reason why, because I need to tell usercontrol_1
    > >> that usercontrol_2 button was clicked and therefore need
    > >> usercontrol_2 public properties to be passed to
    > >> usercontrol_1 public properties in the case of the event.
    > >>
    > >> thanks

    > >
    > >

    >
    >
    >
     
    =?Utf-8?B?d2lsbGlhbQ==?=, Jan 26, 2005
    #5
  6. Joey G

    Teemu Keiski Guest

    Hi,

    See my blog post:

    http://blogs.aspadvice.com/joteke/archive/2004/08/05/1444.aspx

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU



    "william" <> wrote in message
    news:...
    > Hi,
    > How can I know which button cause the postback event in page_load event?
    > Thanks
    >
    >
    > "Joey G" wrote:
    >
    >> Thanks for the response Scott, but that is not the case. I felt the same
    >> way, but the object that caused the postback is only the sender of the
    >> wired
    >> event (i.e. usercontrol_2_button_click(byval sender as....)) and not the
    >> sender of the page_init or page_load.
    >>
    >> "Scott M." <> wrote in message
    >> news:...
    >> > The page load event (as well as most other controls) has a Sender as
    >> > Object argument. Sender is the object that cause the event handler to
    >> > fire.
    >> >
    >> > If you use Sender.GetType.Name, you can get the name of the type that
    >> > caused the postback.
    >> >
    >> >
    >> > "Joey G" <> wrote in message
    >> > news:19cb01c4c764$3c95e510$...
    >> >> How do I get the name or identify the control that caused
    >> >> the page postback. I need the information during page
    >> >> init. Reason why, because I need to tell usercontrol_1
    >> >> that usercontrol_2 button was clicked and therefore need
    >> >> usercontrol_2 public properties to be passed to
    >> >> usercontrol_1 public properties in the case of the event.
    >> >>
    >> >> thanks
    >> >
    >> >

    >>
    >>
    >>
     
    Teemu Keiski, Jan 26, 2005
    #6
    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. Aaron Chorpenning

    Re: How to determine Control that caused Postback?

    Aaron Chorpenning, Jul 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    477
    Aaron Chorpenning
    Jul 21, 2003
  2. Jeff Voigt

    What Control Caused the PostBack?

    Jeff Voigt, Aug 8, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    453
    eruess
    Aug 8, 2003
  3. RTM
    Replies:
    4
    Views:
    2,775
    mikeb
    Jan 20, 2004
  4. Martin
    Replies:
    3
    Views:
    773
    Teemu Keiski
    May 14, 2005
  5. Nathan Sokalski

    Determining What Control Caused The PostBack

    Nathan Sokalski, Sep 5, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    942
    Nathan Sokalski
    Sep 5, 2005
Loading...

Share This Page