Check which button is clicked

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn

    Check which button is clicked

    Hi.
    I have a ToolBar with a couple of ToolBarButtons. On postback after
    clicking on of the buttons Page_Load is called first then the
    ToolBarButton's click event is called. Is there anyway for me to check in
    Page_Load which of the buttons have been clicked?

    Thanks,
    Shawn


  • serge calderara

    #2
    RE: Check which button is clicked

    Is there any way to scan throught the ToolBar collection an object of type
    Button and then by its index value identify that clicked button?



    "Shawn" wrote:
    [color=blue]
    > Hi.
    > I have a ToolBar with a couple of ToolBarButtons. On postback after
    > clicking on of the buttons Page_Load is called first then the
    > ToolBarButton's click event is called. Is there anyway for me to check in
    > Page_Load which of the buttons have been clicked?
    >
    > Thanks,
    > Shawn
    >
    >
    >[/color]

    Comment

    • Kevin Spencer

      #3
      Re: Check which button is clicked

      Write an Event Handler for the ToolBarButton's click event. It isn't
      necessary to use the Page_Load Sub to do all the work in your Page. In fact,
      it isn't necessarily a good idea to do anything in particular in that Sub.
      The Sub is for the purpose of executing processes that must run when the
      Page loads. There are plenty of other events and methods for doing things in
      a Page. See:



      --
      HTH,

      Kevin Spencer
      Microsoft MVP
      ..Net Developer
      Neither a follower nor a lender be.

      "Shawn" <bossman100@hot mail.com> wrote in message
      news:uQs8AJquFH A.992@TK2MSFTNG P12.phx.gbl...[color=blue]
      > Hi.
      > I have a ToolBar with a couple of ToolBarButtons. On postback after
      > clicking on of the buttons Page_Load is called first then the
      > ToolBarButton's click event is called. Is there anyway for me to check in
      > Page_Load which of the buttons have been clicked?
      >
      > Thanks,
      > Shawn
      >
      >[/color]


      Comment

      • Shawn

        #4
        Re: Check which button is clicked

        Kevin,
        In general I don't do any particular work in page_load, but in this case I
        have no choice. I'm adding checkboxes dynamically to my page and in order
        to display them after a postback I have to re-create all of them. As far as
        I know I have to do this in page_load. I tried doing it in
        toolbar_save_Bu ttonClick(), but the checkboxes' state were no longer
        available in ViewState. The reason why I want to know -in page_load- which
        button was clicked, is because re-creation of the checkboxes is dependent on
        which button is clicked, and since I can't re-create them in the buttons
        click event I have to know this in page_load.

        Shawn


        "Kevin Spencer" <kevin@DIESPAMM ERSDIEtakempis. com> wrote in message
        news:%23GS1jbru FHA.252@TK2MSFT NGP09.phx.gbl.. .[color=blue]
        > Write an Event Handler for the ToolBarButton's click event. It isn't
        > necessary to use the Page_Load Sub to do all the work in your Page. In[/color]
        fact,[color=blue]
        > it isn't necessarily a good idea to do anything in particular in that Sub.
        > The Sub is for the purpose of executing processes that must run when the
        > Page loads. There are plenty of other events and methods for doing things[/color]
        in[color=blue]
        > a Page. See:
        >
        >[/color]
        http://msdn.microsoft.com/library/de...nLifecycle.asp[color=blue]
        >
        > --
        > HTH,
        >
        > Kevin Spencer
        > Microsoft MVP
        > .Net Developer
        > Neither a follower nor a lender be.
        >
        > "Shawn" <bossman100@hot mail.com> wrote in message
        > news:uQs8AJquFH A.992@TK2MSFTNG P12.phx.gbl...[color=green]
        > > Hi.
        > > I have a ToolBar with a couple of ToolBarButtons. On postback after
        > > clicking on of the buttons Page_Load is called first then the
        > > ToolBarButton's click event is called. Is there anyway for me to check[/color][/color]
        in[color=blue][color=green]
        > > Page_Load which of the buttons have been clicked?
        > >
        > > Thanks,
        > > Shawn
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Kevin Spencer

          #5
          Re: Check which button is clicked

          You can check the hidden "__EVENTTAR GET" form field in the Request.Form
          Collection, assuming that you have assigned a handler to the button's Click
          event. This will contain the client-side ID of the Control that raised the
          event.

          --
          HTH,

          Kevin Spencer
          Microsoft MVP
          ..Net Developer
          Neither a follower nor a lender be.

          "Shawn" <bossman100@hot mail.com> wrote in message
          news:ubBCw%23ru FHA.3588@tk2msf tngp13.phx.gbl. ..[color=blue]
          > Kevin,
          > In general I don't do any particular work in page_load, but in this case I
          > have no choice. I'm adding checkboxes dynamically to my page and in order
          > to display them after a postback I have to re-create all of them. As far
          > as
          > I know I have to do this in page_load. I tried doing it in
          > toolbar_save_Bu ttonClick(), but the checkboxes' state were no longer
          > available in ViewState. The reason why I want to know -in page_load-
          > which
          > button was clicked, is because re-creation of the checkboxes is dependent
          > on
          > which button is clicked, and since I can't re-create them in the buttons
          > click event I have to know this in page_load.
          >
          > Shawn
          >
          >
          > "Kevin Spencer" <kevin@DIESPAMM ERSDIEtakempis. com> wrote in message
          > news:%23GS1jbru FHA.252@TK2MSFT NGP09.phx.gbl.. .[color=green]
          >> Write an Event Handler for the ToolBarButton's click event. It isn't
          >> necessary to use the Page_Load Sub to do all the work in your Page. In[/color]
          > fact,[color=green]
          >> it isn't necessarily a good idea to do anything in particular in that
          >> Sub.
          >> The Sub is for the purpose of executing processes that must run when the
          >> Page loads. There are plenty of other events and methods for doing things[/color]
          > in[color=green]
          >> a Page. See:
          >>
          >>[/color]
          > http://msdn.microsoft.com/library/de...nLifecycle.asp[color=green]
          >>
          >> --
          >> HTH,
          >>
          >> Kevin Spencer
          >> Microsoft MVP
          >> .Net Developer
          >> Neither a follower nor a lender be.
          >>
          >> "Shawn" <bossman100@hot mail.com> wrote in message
          >> news:uQs8AJquFH A.992@TK2MSFTNG P12.phx.gbl...[color=darkred]
          >> > Hi.
          >> > I have a ToolBar with a couple of ToolBarButtons. On postback after
          >> > clicking on of the buttons Page_Load is called first then the
          >> > ToolBarButton's click event is called. Is there anyway for me to check[/color][/color]
          > in[color=green][color=darkred]
          >> > Page_Load which of the buttons have been clicked?
          >> >
          >> > Thanks,
          >> > Shawn
          >> >
          >> >[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          Working...