Dynamically click button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?c21heQ==?=

    #1

    Dynamically click button

    I'm trying to raise the click event of a button from my Page_Load event so
    that after the Page_Load completes the myBtn_Click event is fired, just as if
    a user had clicked the button. I can't just call myBtn_Click, page_load must
    complete first just as it would if a user had clicked. I keep getting an
    error telling me to set the page's EnableEventVali dation to false, but I
    don't want to do that. For testing, I did set it to false and used
    "DirectCast(myB tn, IPostBackEventH andler).RaisePo stBackEvent(Not hing)" to
    raise the click event, but myBtn_Click was called immediately, not after
    Page_Load.

    Can anyone help with a specific VB example?
  • David Wier

    #2
    Re: Dynamically click button

    I'd suggest putting the entire action you have inside the click event into
    its own subroutine -
    Then, in the click event of the button, just call that subroutine

    That way, you can call the routine in anyway you'd like from anywhere
    (dynamically or otherwise)

    David Wier

    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "smay" <smay@discussio ns.microsoft.co mwrote in message
    news:278D4083-B9B2-4E20-9E55-C3AF08E85085@mi crosoft.com...
    I'm trying to raise the click event of a button from my Page_Load event so
    that after the Page_Load completes the myBtn_Click event is fired, just as
    if
    a user had clicked the button. I can't just call myBtn_Click, page_load
    must
    complete first just as it would if a user had clicked. I keep getting an
    error telling me to set the page's EnableEventVali dation to false, but I
    don't want to do that. For testing, I did set it to false and used
    "DirectCast(myB tn, IPostBackEventH andler).RaisePo stBackEvent(Not hing)" to
    raise the click event, but myBtn_Click was called immediately, not after
    Page_Load.
    >
    Can anyone help with a specific VB example?

    Comment

    • Patrice

      #3
      Re: Dynamically click button

      You could have this code in its own routine so that your handlers (or
      whetver place you want) can just call the real sttuff (rather than
      "embedding" this code).

      Else you could use LoadComplete if you really need to have this done after
      page_load (not even at the end of this event).

      As usual knowing a bit more what you are trying to do (and why you need to
      fake a user click) could raise more focused suggestions...

      --
      Patrice

      "smay" <smay@discussio ns.microsoft.co ma écrit dans le message de news:
      278D4083-B9B2-4E20-9E55-C3AF08E85085@mi crosoft.com...
      I'm trying to raise the click event of a button from my Page_Load event so
      that after the Page_Load completes the myBtn_Click event is fired, just as
      if
      a user had clicked the button. I can't just call myBtn_Click, page_load
      must
      complete first just as it would if a user had clicked. I keep getting an
      error telling me to set the page's EnableEventVali dation to false, but I
      don't want to do that. For testing, I did set it to false and used
      "DirectCast(myB tn, IPostBackEventH andler).RaisePo stBackEvent(Not hing)" to
      raise the click event, but myBtn_Click was called immediately, not after
      Page_Load.
      >
      Can anyone help with a specific VB example?

      Comment

      • =?Utf-8?B?c21heQ==?=

        #4
        Re: Dynamically click button

        Problem is the button is not visible to the user. It was just my way of
        forcing code to run after the Page_Load completes. Any suggestions on a
        better/different way?

        "David Wier" wrote:
        I'd suggest putting the entire action you have inside the click event into
        its own subroutine -
        Then, in the click event of the button, just call that subroutine
        >
        That way, you can call the routine in anyway you'd like from anywhere
        (dynamically or otherwise)
        >
        David Wier

        http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
        bloated markup
        >
        >
        "smay" <smay@discussio ns.microsoft.co mwrote in message
        news:278D4083-B9B2-4E20-9E55-C3AF08E85085@mi crosoft.com...
        I'm trying to raise the click event of a button from my Page_Load event so
        that after the Page_Load completes the myBtn_Click event is fired, just as
        if
        a user had clicked the button. I can't just call myBtn_Click, page_load
        must
        complete first just as it would if a user had clicked. I keep getting an
        error telling me to set the page's EnableEventVali dation to false, but I
        don't want to do that. For testing, I did set it to false and used
        "DirectCast(myB tn, IPostBackEventH andler).RaisePo stBackEvent(Not hing)" to
        raise the click event, but myBtn_Click was called immediately, not after
        Page_Load.

        Can anyone help with a specific VB example?
        >
        >
        >

        Comment

        • David Wier

          #5
          Re: Dynamically click button

          As Patrice said - you can call the routine I suggested in either the
          LoadComplete or PreRender events


          David Wier

          http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
          bloated markup


          "smay" <smay@discussio ns.microsoft.co mwrote in message
          news:BB96663F-202B-4805-91BA-2A38CBBB16A9@mi crosoft.com...
          Problem is the button is not visible to the user. It was just my way of
          forcing code to run after the Page_Load completes. Any suggestions on a
          better/different way?
          >
          "David Wier" wrote:
          >
          >I'd suggest putting the entire action you have inside the click event
          >into
          >its own subroutine -
          >Then, in the click event of the button, just call that subroutine
          >>
          >That way, you can call the routine in anyway you'd like from anywhere
          >(dynamically or otherwise)
          >>
          >David Wier
          >http://aspnet101.com
          >http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
          >no
          >bloated markup
          >>
          >>
          >"smay" <smay@discussio ns.microsoft.co mwrote in message
          >news:278D408 3-B9B2-4E20-9E55-C3AF08E85085@mi crosoft.com...
          I'm trying to raise the click event of a button from my Page_Load event
          so
          that after the Page_Load completes the myBtn_Click event is fired, just
          as
          if
          a user had clicked the button. I can't just call myBtn_Click,
          page_load
          must
          complete first just as it would if a user had clicked. I keep getting
          an
          error telling me to set the page's EnableEventVali dation to false, but
          I
          don't want to do that. For testing, I did set it to false and used
          "DirectCast(myB tn, IPostBackEventH andler).RaisePo stBackEvent(Not hing)"
          to
          raise the click event, but myBtn_Click was called immediately, not
          after
          Page_Load.
          >
          Can anyone help with a specific VB example?
          >>
          >>
          >>

          Comment

          Working...