Strange ASP.NET Submit Button Behavior

Posted on 2006-04-19
Last Modified: 2009-12-16
Hi Experts,

I'm having a lot of trouble with this one.

A simple textbox control and a button control.  If a visitor types a number into the textbox, and then clicks the 'submit' button with the mouse, the onclick event runs a subroutine that does a membership check.  All is well.

However, if the person simply types their member number into the text box and presses ENTER, the page appears to post back but no data is processed.

Any idea what is going on?  This is driving me NUTS!!

Here's the complete code.  Any help would be appreciated.

<%@ Page Language="VB" EnableViewState="false" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Register Assembly="PeterBlum.VAM" Namespace="PeterBlum.VAM" TagPrefix="VAM" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="" xml:lang="en">
<script runat="server">
    Protected Sub btnCheckAccount_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim MyConnection As SqlConnection
        Dim MyCommand As SqlCommand
        Dim MyReader As SqlDataReader
        Dim IDParam As SqlParameter
        Dim CheckIfActive As Boolean
        Dim CheckEmailAddress As String
        MyConnection = New SqlConnection(ConfigurationManager.AppSettings("MM_CONNECTION_STRING_APDTMain"))
        MyCommand = New SqlCommand()
        MyCommand.CommandText = "SELECT * from vw_MemberStatusCheck WHERE Account = @ID"
        MyCommand.CommandType = CommandType.Text
        MyCommand.Connection = MyConnection
        IDParam = New SqlParameter()
        IDParam.ParameterName = "@ID"
        IDParam.Value = txtAccount.Text
        MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection)
        pnlNoRecords.Visible = True
        pnlActive.Visible = False
        pnlExpired.Visible = False
        While MyReader.Read
            txtDateExpire.Text = MyReader("DateExpire").ToString()
            txtFirstName.Text = MyReader("FirstName")
            txtFirstNameActive.Text = MyReader("FirstName")
            txtMemberType.Text = MyReader("MemberType")
            cbxActive.Checked = MyReader("Active")
            txtAccount.Text = MyReader("Account")
            CheckIfActive = MyReader("InitialSuccessPmt")
            CheckEmailAddress = MyReader("Email")
            If cbxActive.Checked = True Then
                pnlActive.Visible = True
                pnlExpired.Visible = False
                pnlNoRecords.Visible = False

            End If
            If cbxActive.Checked = False Then
                pnlExpired.Visible = True
                pnlActive.Visible = False
                pnlNoRecords.Visible = False
            End If
            If CheckIfActive = True Then
                pnlNotYetActive.Visible = True
                pnlSendEmail.Visible = True
                pnlExpired.Visible = False
                pnlActive.Visible = False
                pnlNoRecords.Visible = False
            End If
        End While
    End Sub
</script><title>Forgot Your Password?</title>
<!--#include virtual="/assets/inc/cmn/" -->
<style type="text/css" media="all">
table.tablelistnb td.lbl{padding-right:0;}
#bkground{padding-bottom:7px;margin-top:10px;margin-bottom:10px;border:1px solid #ccc;background:#F7F7FA;width:350px;}
<script type="text/JavaScript" src="/assets/js/popup.js"></script>
<body id="twocol">
<h1 Membership Status</h1>
<p>Enter your Member Number in the box below to check your APDT Membership status.</p>
<form id="frmLogin" style="margin-bottom: 0.5em" runat="server">
<table border="0" cellpadding="0" cellspacing="0" class="tablelistnb">
<td nowrap="nowrap" class="lbl" style="text-align:right"><label for="txtUsername">APDT Member #</label></td>
<td width="100%"><asp:TextBox ID="txtAccount" runat="server" Size="6" MaxLength="6" TabIndex="1" ToolTip="Type your APDT Membership Number in this box." /> <span class="small"><VAM:DataTypeCheckValidator ID="DataTypeCheckValidator1" runat="server" ControlIDToEvaluate="txtAccount"
        DataType="Integer" ErrorFormatter="Text (class: TextErrorFormatter)" ErrorMessage="Numbers only, please.">
            <VAM:TextErrorFormatter Display="Dynamic" ForeColor="Red" />
    <VAM:RequiredTextValidator ID="RequiredTextValidator1" runat="server" ControlIDToEvaluate="txtAccount"
        ErrorFormatter="Red Error Message (class: TextErrorFormatter)" ErrorMessage="Enter Member Number.">
            <VAM:TextErrorFormatter Display="Dynamic" Font-Bold="False" Font-Italic="False" Font-Overline="False"
                Font-Strikeout="False" Font-Underline="False" ForeColor="Red" Name="Red Error Message" />

<td colspan="2" class="textalgnctr">
 <asp:Button ID="btnCheckAccount" runat="server" Text="Check My Status" OnClick="btnCheckAccount_Click" /></td>

<asp:Panel ID="pnlExpired" runat="server" Visible="false">
<p><asp:Literal ID="txtFirstName" runat="server"></asp:Literal>, it seems that your membership expired on <asp:Literal ID="txtDateExpire" runat="server"></asp:Literal>.&nbsp; Renew now &gt;</p>
<asp:Panel ID="pnlActive" runat="server" Visible="false"><p> <asp:Literal ID="txtFirstNameActive" runat="server"></asp:Literal>, you are an active: <asp:Literal ID="txtMemberType" runat="server"></asp:Literal>.</p>

<asp:Panel ID="pnlSendEmail" runat="server" Visible="false">    
<p>Did you need your password sent to your email address?  If so, you may do so now:</p>
<p><asp:Button ID="btnSendEmail" runat="server" Text="Send My Password" /></p>

<asp:CheckBox ID="cbxActive" runat="server" Visible="false"/>
 <asp:Panel ID="pnlNoRecords" runat="server" Visible="false">

<p> No Records Found.  Please enter a valid Member Number.</p></asp:Panel>
    <asp:Panel ID="pnlNotYetActive" runat="server" Visible="false">
<p>Be patient, you are not yet active.</p>


Question by:jumpseatnews
    LVL 7

    Accepted Solution

    Change your Body tag to the following code and make sure your btnCheckAccount's CausesValidation Property is set to TRUE
    <body id="twocol" onkeydown="if(event.keyCode == 13){document.getElementById('btnCheckAccount').click();}">

    Happy Programming

    Author Comment

    Hey Rana!

    Thank you.  That's exactly what I was looking for.  Problem solved!

    Happy Programming!


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now