• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

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!

2 Solutions

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now