Dynamic Button OnClick not firing

Discussion in 'ASP General' started by John Harte, Jan 14, 2008.

  1. John Harte

    John Harte Guest

    Hi,

    In the code behind of my ASP.net web page I have code written that is
    dynamically creating a button. Here is a sample of how I define it.

    //Define Variable
    Button btnNext;

    public void someMethod()
    {
    btnNext = new Button();
    button += new EventHandler(this.btnNext_Click);
    //then i add the control to the page, then call its click event
    btnNext_Click();
    }

    When I clickthis button on the page, the page postsback and its onclick
    event is never called (stepping through the code shows that it never gets
    reached). If I click the button a second time, the method is called and it
    works fine.

    Im not sure if there is any more information I can give, and help would be
    greatly appreciated

    John Harte
     
    John Harte, Jan 14, 2008
    #1
    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. Vikram

    button server onclick not firing

    Vikram, Feb 1, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,469
    Patrick.O.Ige
    Feb 2, 2006
  2. Replies:
    7
    Views:
    12,427
  3. SAL
    Replies:
    9
    Views:
    771
  4. Jer

    JavaScript Onclick firing a button (C#)

    Jer, Nov 28, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    386
    Alan Z. Scharf
    Nov 29, 2004
  5. Replies:
    2
    Views:
    261
Loading...

Share This Page