Add OnClick button event dynamically

Discussion in 'ASP .Net' started by anony, Dec 14, 2003.

  1. anony

    anony Guest

    Hi,

    I'm trying to dynamically add a button to my ASP.NET / VB page. I can't
    seem to figure out how to add a routine to the OnClick event. Any insight
    would be greatly appreciated!

    Thanks,
    Brian
    anony, Dec 14, 2003
    #1
    1. Advertising

  2. To add a server-side event handler, use the following code:

    MyButton.Click += new System.EventHandler(MyButton_Click)

    where MyButton_Click is as follows:

    private void MyButton_Click (object sender, System.EventArgs e)
    {
    // Your button click code here.
    }

    If you want to do something client-side in the onClick event, use:

    myButton.Attributes.Add("onClick", "fnClientSideThing()");

    This code will fire the client-side javascript function called
    fnClientSideThing() when the button is clicked.

    Hope this helps,

    Mun




    "anony" <> wrote in message
    news:Xt%Cb.15334$...
    > Hi,
    >
    > I'm trying to dynamically add a button to my ASP.NET / VB page. I can't
    > seem to figure out how to add a routine to the OnClick event. Any insight
    > would be greatly appreciated!
    >
    > Thanks,
    > Brian
    Munsifali Rashid, Dec 14, 2003
    #2
    1. Advertising

  3. Carl Prothman [MVP], Dec 14, 2003
    #3
    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. Ryan Taylor
    Replies:
    2
    Views:
    14,593
    maclade
    Mar 20, 2008
  2. Replies:
    7
    Views:
    12,406
  3. Rocky
    Replies:
    0
    Views:
    258
    Rocky
    Nov 8, 2006
  4. cool2005

    dynamically add a table row with onclick

    cool2005, May 8, 2005, in forum: Javascript
    Replies:
    8
    Views:
    161
    Richard Cornford
    May 9, 2005
  5. Replies:
    2
    Views:
    239
Loading...

Share This Page