Button Command not even executing...

Here's the text of an ASP.NET page I'm trying to get to work...Nothing inside the btnGo_Click() executes and I have no idea why...

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

            <meta name="vs_snapToGrid" content="True">
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <DIV id="DIV1" style="DISPLAY: inline; Z-INDEX: 101; LEFT: 16px; WIDTH: 216px; POSITION: absolute; TOP: 16px; HEIGHT: 38px"
                        runat="server" ms_positioning="FlowLayout">This site will add shit to the Dummy DB</DIV>
                  <asp:TextBox id="txtName" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 64px"
                        runat="server" Width="216px" Height="32px">Name</asp:TextBox>
                  <asp:TextBox id="txtD" style="Z-INDEX: 103; LEFT: 24px; POSITION: absolute; TOP: 112px" runat="server"
                        Width="216px" Height="32px">Description</asp:TextBox>
                  <asp:Button id="btnGo" style="Z-INDEX: 105; LEFT: 24px; POSITION: absolute; TOP: 208px" runat="server"
                        Width="224px" Height="48px" Text="Add Dummy"></asp:Button>

<script language="VB" runat="server">
Dim objConnection As SqlConnection

Sub Page_Load(Source as Object, E as EventArgs)

  ' Create a new connection object pointing to the database
  Dim strConnection As String = ConfigurationSettings.AppSettings("subrodog")
  objConnection = New SqlConnection(strConnection)
  'Response.Write("Page Loaded.")
End Sub

Sub btnGo_Click(Sender As Object, E As EventArgs)
      Response.Write("I like chickens!")
  If Page.IsValid Then
    Dim strSQL As String="INSERT INTO DUMMY VALUES(@Name, @D)"

    Dim dbComm As New SqlCommand(strSQL, objConnection)
    dbComm.Parameters.Add("@Name", SqlDbType.varchar, 10)
    dbComm.Parameters.Add("@D", SqlDbType.varchar, 10)

    dbComm.Parameters("@Name").Value = txtName.Text
    dbComm.Parameters("@D").Value = txtD.Text

      Response.Write("It got this far at least")

    Dim iID as Integer
      iID = dbComm.ExecuteScalar()
    Catch ex As Exception
      If objConnection.State = ConnectionState.Open Then
      End If
    End Try

    Response.Write("The ID of the new record is: " & iID.ToString())
  End If
End Sub

The actual page itself can be found at the following URL (unless I've shut down the server for the night by the time you read this...)


Thanks for any help!

Who is Participating?

try adding OnClick event to the button control, change your asp:button tag to something like this,

              <asp:Button id="btnGo" style="Z-INDEX: 105; LEFT: 24px; POSITION: absolute; TOP: 208px" runat="server"
                    Width="224px" Height="48px" Text="Add Dummy" OnClick="btnGo_Click"></asp:Button>

Even i had problems like this before..that time what i did was that , i created a new asp.net application ,created a new button  and copy/paste the code in that applciation. It worked for me that time..See if this helps u

all the best

Anthony PerkinsCommented:
That is because you are missing the handler, something like:
Sub btnGo_Click(Sender As Object, E As EventArgs) Handles btnGo.Click

The same goes for the Page_Load event, it should be something like:
Sub Page_Load(Source as Object, E as EventArgs) Handles MyBase.Load
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.