Call event handler programatically

Discussion in 'ASP .Net' started by mg, Nov 28, 2003.

  1. mg

    mg Guest

    How can I call an event handler (e.g., Button1_Click)
    programmatically. That is, without having to click on the
    button with the mouse.
     
    mg, Nov 28, 2003
    #1
    1. Advertising

  2. mg

    mg Guest

    That's with C# in the code behind of a WebForm


    >-----Original Message-----
    >How can I call an event handler (e.g., Button1_Click)
    >programmatically. That is, without having to click on

    the
    >button with the mouse.
    >.
    >
     
    mg, Nov 28, 2003
    #2
    1. Advertising

  3. mg wrote:
    > How can I call an event handler (e.g., Button1_Click)
    > programmatically. That is, without having to click on the
    > button with the mouse.


    It's just a method like any other. So long as you pass the correct
    number and type of parameters, you're free to call it any time you like.

    Personally, I tend to code such that my event handlers pass their
    arguments to a different routine. I do so for just this sort of
    situation.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Nov 28, 2003
    #3
  4. mg

    mg Guest

    I've tried Button1_Click(null, null) and a few other
    arguments when calling Button1_Click from within some
    other method in the code behind ... but can't get the "do
    something here" code to run. Can you give me something
    more specific on how the Button1_Click method can be
    called?


    private void Button1_Click(object sender,
    System.EventArgs e)
    {
    // do something here
    }

    Thanks!

    >-----Original Message-----
    >mg wrote:
    >> How can I call an event handler (e.g., Button1_Click)
    >> programmatically. That is, without having to click on

    the
    >> button with the mouse.

    >
    >It's just a method like any other. So long as you pass

    the correct
    >number and type of parameters, you're free to call it

    any time you like.
    >
    >Personally, I tend to code such that my event handlers

    pass their
    >arguments to a different routine. I do so for just this

    sort of
    >situation.
    >
    >--
    >There are 10 kinds of people. Those who understand

    binary and those who
    >don't.
    >
    >http://code.acadx.com
    >(Pull the pin to reply)
    >
    >
    >.
    >
     
    mg, Nov 28, 2003
    #4
  5. mg wrote:
    > I've tried Button1_Click(null, null)


    Have you tried Button1_Click(this, new EventArgs())?

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Nov 29, 2003
    #5
  6. mg

    mg Guest

    I've misrepresented my problem :-(

    I'll now post a new message with a restatement of the
    problem.


    >-----Original Message-----
    >I've tried Button1_Click(null, null) and a few other
    >arguments when calling Button1_Click from within some
    >other method in the code behind ... but can't get

    the "do
    >something here" code to run. Can you give me something
    >more specific on how the Button1_Click method can be
    >called?
    >
    >
    >private void Button1_Click(object sender,
    >System.EventArgs e)
    >{
    > // do something here
    >}
    >
    >Thanks!
    >
    >>-----Original Message-----
    >>mg wrote:
    >>> How can I call an event handler (e.g., Button1_Click)
    >>> programmatically. That is, without having to click on

    >the
    >>> button with the mouse.

    >>
    >>It's just a method like any other. So long as you pass

    >the correct
    >>number and type of parameters, you're free to call it

    >any time you like.
    >>
    >>Personally, I tend to code such that my event handlers

    >pass their
    >>arguments to a different routine. I do so for just this

    >sort of
    >>situation.
    >>
    >>--
    >>There are 10 kinds of people. Those who understand

    >binary and those who
    >>don't.
    >>
    >>http://code.acadx.com
    >>(Pull the pin to reply)
    >>
    >>
    >>.
    >>

    >.
    >
     
    mg, Nov 29, 2003
    #6
  7. mg

    Onur Gorur Guest

    MG,

    If you want to raise the event programatically use

    RaiseEvent(button1.click) function!. (refer help on use :)

    if you want to add a function in run time then use

    addhandler a.click, addressof b

    where a is control, b is your handler function

    Onur



    "mg" <> wrote in message
    news:910e01c3b606$031a7370$...
    > How can I call an event handler (e.g., Button1_Click)
    > programmatically. That is, without having to click on the
    > button with the mouse.
     
    Onur Gorur, Nov 30, 2003
    #7
  8. Jackie foster, Aug 3, 2006
    #8
    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. mg
    Replies:
    2
    Views:
    3,106
    Robsta
    Jan 7, 2009
  2. Richard Morse
    Replies:
    3
    Views:
    1,051
    Corey O'Mara
    Feb 7, 2004
  3. =?Utf-8?B?RWQgQ2hpdQ==?=

    Call an event handler programatically

    =?Utf-8?B?RWQgQ2hpdQ==?=, Sep 13, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    529
    Peter Rilling
    Sep 13, 2005
  4. Replies:
    1
    Views:
    707
    Damien
    Feb 22, 2007
  5. mg

    Invoke event handler programatically

    mg, Jul 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    133
Loading...

Share This Page