Results 1 to 8 of 8

Thread: Button click not firing

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Atlanta
    Posts
    24

    Button click not firing

    I have a problem with a web form I am developing. The problem is that the button click event does not fire when the user presses the button- the page re-loads, but the code behind the button never gets executed.

    Admitedly I am a little new to this (and mainly a VB6 guy), so it is possible that I am missing an important concept here- but I have used buttons on other web forms before and had no problems. The main difference is that on this form the button is nested inside a table (though if I move it out, it still does not work).

    There is also a calendar control and a few scrolling datagrids on the form- nothing fancy.

    Button code is as follows
    Code:
    <P align="center">
    <FONT face="Arial">
    <asp:button id="cmdAddJob" 
    runat="server" Text="Add Job" Height="22px" Width="96px">
    Code behind is quite simple:

    VB Code:
    1. Private Sub cmdAddJob_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddJob.Click
    2.  
    3.         AddTempJob()
    4.  
    5.     End Sub

    Thanks for any help!

  2. #2
    Junior Member Sami Antero's Avatar
    Join Date
    Jun 2005
    Location
    Helsinki, Finland
    Posts
    16

    Re: Button click not firing

    Hi! Have you got this declared in your code behind(at the top of your webform class?)

    Code:
    Protected WithEvents cmdAddJob As System.Web.UI.WebControls.Button

    tsami
    Sami Antero
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    no smileys, no funky certificates. Sorry.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Atlanta
    Posts
    24

    Re: Button click not firing

    Yes.

  4. #4
    Junior Member Sami Antero's Avatar
    Join Date
    Jun 2005
    Location
    Helsinki, Finland
    Posts
    16

    Re: Button click not firing

    ...and you've closed the button tag?

    Code:
    <asp:button id="cmdAddJob" runat="server" Font-Names="Arial"></asp:button>
    Are you working with vs2003 btw? If you are, go to the designer mode and double click your button to ensure that the event wiring is ok.

    tsami
    Sami Antero
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    no smileys, no funky certificates. Sorry.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Atlanta
    Posts
    24

    Re: Button click not firing

    Sorry, yes, I did close the tag, and the designer behaves as expected.

  6. #6
    Lively Member
    Join Date
    Feb 2005
    Posts
    121

    Re: Button click not firing

    dear friend

    i dont know bout vb much.how does i work

    but while working in C# as codebehind i faced siimilar problem .for that we have to write systemhandler for the control if it is missing in initializecomponent.

    hope this helps

    you can find similar thing for VB

    -Sachien

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Atlanta
    Posts
    24

    Re: Button click not firing

    Well, more info but more puzzling:

    I can re-create the page by adding new controls and get something that works as expected.

    I noticed that if I move the button to another location it can 'break' the click event- removes the Handles cmdAddJob.click from the event code ?!?

    I can get it working now but I am stumped as to what causes the behavior.
    Last edited by D22353; Jun 22nd, 2005 at 12:31 PM.

  8. #8
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Button click not firing

    The designer will mess you up. Use html view at all times if you can. also a sure fire way to have your event fire is to set onclick="name_of_click_handler" in the button tag.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width