• 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" %>

<HTML>
      <HEAD>
            <meta name="vs_snapToGrid" content="True">
            <title>WebForm1</title>
            <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">
      </HEAD>
      <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>
            </form>
      </body>
</HTML>

<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
    Try
      objConnection.Open()
      iID = dbComm.ExecuteScalar()
    Catch ex As Exception
      Response.Write(ex.Message)
      Response.End
    Finally
      If objConnection.State = ConnectionState.Open Then
        objConnection.Close()
      End If
    End Try

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


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...)

www.pinnaclesubro.com/test.aspx

Thanks for any help!

0
brassmonkeyboy
Asked:
brassmonkeyboy
2 Solutions
 
appariCommented:

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>
0
 
techbieCommented:
Hi...

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

techbie
0
 
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
0

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