Results 1 to 9 of 9

Thread: [RESOLVED] Code Not Executing (button)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    99

    Resolved [RESOLVED] Code Not Executing (button)

    I'm just getting into ASP.NET, so please excuse my ignorance.

    I've added a button to my page and have added code to the _Click event, but the code doesn't execute when clicked. I've put a break on each line but it runs right through when clicked. It's clearly not a problem with the code in this button since it doesn't execute it, but i'll toss it in here anyways just for fun.

    vb Code:
    1. Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    2.         Context.Items.Add("custnum", txtSQL.Text)
    3.        
    4.         Server.Transfer("custnum.aspx", True)
    5.     End Sub

    I'm assuming it's something very simple. Any ideas? Yes, the button name is correct, btw.

  2. #2
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: Code Not Executing (button)

    Try
    Code:
    Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    99

    Re: Code Not Executing (button)

    Quote Originally Posted by rjv_rnjn View Post
    Try
    Code:
    Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
    no good

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    99

    Re: Code Not Executing (button)

    Quote Originally Posted by Eclyps19 View Post
    no good
    I added an additional button directly after my textbox and copied the code into there, which seems to work just fine. Here's a clip.

    vb Code:
    1. <p align="left">
    2.     Please type the Customer Number:
    3.     <asp:TextBox ID="txtSQL" runat="server" Width="660px"
    4.         ontextchanged="txtSQL_TextChanged"></asp:TextBox>
    5.        'Works!
    6.        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    7. </p>
    8. <p align="left">
    9.        'Doesn't work!
    10.         <asp:Button ID="cmdSubmit" runat="server" onclick="cmdSubmit_Click"
    11.         Text="Submit SQL" />
    12. </p>

    still can't figure out why one works and the other doesn't...

  5. #5
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: Code Not Executing (button)

    Is there any difference on the event handler signature of two buttons?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    99

    Re: Code Not Executing (button)

    Quote Originally Posted by rjv_rnjn View Post
    Is there any difference on the event handler signature of two buttons?
    nothing other than the name

    vb Code:
    1. Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    2. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Code Not Executing (button)

    Hey,

    Basically, events, like the Button Click event, need to be hooked up to their associated Event Handlers. In VB.net, this linkage happens with the use of the Handles Clause which rjv_rnjn pointed you at. Quite why this didn't work for you, I am at a loss to say, but one way to check would be the following:

    1) In Design View, select your button
    2) Bring up the Properties window, and then click the yello lightning bolt
    3) Select the Event that you are interested in, in your case the click event, and then hit the drop down list beside (you may or may not already have a event handler specified.
    4) Select the event handler that you want to associate with this event.

    Here is a screen shot:

    Name:  Button Click Event Handler.jpg
Views: 141
Size:  26.3 KB

    Hope that helps!!

    Gary

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    99

    Re: Code Not Executing (button)

    Quote Originally Posted by gep13 View Post
    Hey,

    Basically, events, like the Button Click event, need to be hooked up to their associated Event Handlers. In VB.net, this linkage happens with the use of the Handles Clause which rjv_rnjn pointed you at. Quite why this didn't work for you, I am at a loss to say, but one way to check would be the following:

    1) In Design View, select your button
    2) Bring up the Properties window, and then click the yello lightning bolt
    3) Select the Event that you are interested in, in your case the click event, and then hit the drop down list beside (you may or may not already have a event handler specified.
    4) Select the event handler that you want to associate with this event.

    Here is a screen shot:

    Name:  Button Click Event Handler.jpg
Views: 141
Size:  26.3 KB

    Hope that helps!!

    Gary
    that helped. Appreciate it!

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Code Not Executing (button)

    Hey,

    Good stuff, glad to hear you got it working!

    Gary

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