Button Command not even executing...

Posted on 2005-05-02
Last Modified: 2012-05-05
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="">
      <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!

Question by:brassmonkeyboy
    LVL 39

    Accepted Solution


    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>
    LVL 5

    Expert Comment


    Even i had problems like this before..that time what i did was that , i created a new 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

    LVL 75

    Assisted Solution

    by:Anthony Perkins
    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now