I am setting up a webpage on our intranet to search for xray history.
Using ASP.NET in Visual Studio.
When I run the program using the First and Last Name search it works fine.
When I run the program using the Medical Record (MR) search....it works when I hit enter but not when I click on the "Find Patient" button the first time.
When I click on the Find Patient button the first time it looks like it reloads the page and then the second time I click on the Find Patient button it works.
So, I enter a different MR number and click Find...there is a little flash or refresh ...then if I click it again it will find the correct information.
Hopefully I've described it well enough for you to help me.
I think my problem is I am not checking for Page.IsPostBack.
But how can I do that if I cannot do that on Load_Page because I need the users input?

Here is my code:

Code:
Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm1
    Inherits System.Web.UI.Page
    'Protected WithEvents grdPatient As System.Web.UI.WebControls.DataGrid
    'Declare a global Connection object 
    Dim objConnection As SqlConnection

#Region " Web Form Designer Generated Code "

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        'Initialize the Connection Object...
        'Set the connection string in the web.config for better security etc.
        objConnection = New SqlConnection
        objConnection.ConnectionString = ConfigurationSettings.AppSettings.Get("ConnectionString")

        'Open the connection to the SQL server
        objConnection.Open()

        'Call JavaScript Sub to set focus to the MedRec TextBox
        Set_Focus(txtGetMedRec)

    End Sub

    'Find Patient Button Execute
    '------------------------------------------------------------------------------------------------
    Private Sub btnFindPatient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindPatient.Click
        'Declare Objects...
        Dim objDataSet As DataSet
        Dim objDataAdapter As SqlDataAdapter
        Dim objSQLCmd As SqlCommand
        Dim objSQLDR As SqlDataReader
        Dim strLName As String
        Dim strFName As String
        Dim strMed_REC As String

        lblCantFindPat.Visible = False
        grdPatient.Dispose()    'Get rid of pre-existing data
        grdPatient.Visible = False  'Hide the grid for now
        grdPatient.DataBind()

        strFName = txtGetFName.Text & "%" 'Set the entry on the form to the parameter.  The % is a wildcard.
        strLName = txtGetLName.Text

        'Create a SQL Command Object to query Patient by Name
        objSQLCmd = New SqlCommand

        If txtGetMedRec.Text <> "" Then  'Search by Med Rec Number
            strMed_REC = txtGetMedRec.Text
            GetPatientByMedRec(strMed_REC)

        Else Then 'Search by Name
            'Define the command with the SQL Stored Procedure info
            With objSQLCmd
                .CommandText = "sp_GetPatientByName" 'Running this Stored Procedure
                .CommandType = CommandType.StoredProcedure
                .Connection = objConnection  'Using this global defined connector
                .Parameters.Add("@LName", SqlDbType.Char).Value = strLName  'set the parameter
                .Parameters.Add("@FName", SqlDbType.Char).Value = strFName  'set the parameter
            End With

            'The next several lines populate the drop down list 
            ddlPatient.Visible = True
            objDataAdapter = New SqlDataAdapter(objSQLCmd)
            objDataSet = New DataSet
            objDataAdapter.Fill(objDataSet)
            ddlPatient.DataSource = objDataSet
            ddlPatient.DataTextField = "Full_Name"
            ddlPatient.DataValueField = "Med_Rec#"
            ddlPatient.DataBind()
            ddlPatient.Items.Insert(0, "Select a Patient")
            ddlPatient.AutoPostBack = True

    End Sub

    'This sub accepts the users selection on the drop down list for the Patient
    Private Sub ddlPatient_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlPatient.SelectedIndexChanged
        Dim strMed_REC As String
        ddlPatient.Visible = False
        strMed_REC = ddlPatient.SelectedItem.Value  'This sets the what the user selected to the variable
        GetPatientByMedRec(strMed_REC)  'Calling this procedure and passing it the MedRec# we got from the users
    End Sub

    Private Sub GetPatientByMedRec(ByVal strMed_Rec As String)
        'Declare objects.....
        Dim objSQLCmd As SqlCommand
        Dim objSQLDR As SqlDataReader
        Dim objDataSet As DataSet
        Dim objDataAdapter As SqlDataAdapter
        Dim strRsltMedRec As String
        Dim strRsltRad As String
        Dim strRsltPatient As String
        Dim strRsltSex As String
        Dim strRsltBirthDate As String
        Dim strRsltSocSec As String
        Dim strRsltLastExam As String

        'lblMedRec.Text = strMed_Rec
        objSQLCmd = New SqlCommand
        With objSQLCmd
            .CommandText = "sp_GetPatientByMedRec" 'Running this Stored Procedure
            .CommandType = CommandType.StoredProcedure
            .Connection = objConnection  'Using this global defined connector
            .Parameters.Add("@MedRec", SqlDbType.Char).Value = strMed_Rec  'set the parameter
        End With
        'Load the SQL DataReader
        objSQLDR = objSQLCmd.ExecuteReader

        If Not objSQLDR.Read() Then
            'Couldn't find the Medical Record #
            'Inform the user
            Exit Sub
        Else
            'Found a match on the Med Rec #
            'Place the query Results into the result strings
            strRsltMedRec = objSQLDR.GetString(0)
            strRsltRad = objSQLDR.GetString(1)
            strRsltPatient = objSQLDR.GetString(3) & ", " & objSQLDR.GetString(2) 'LName, FName
            strRsltSex = objSQLDR.GetString(4)
            strRsltBirthDate = objSQLDR.GetString(5)
            strRsltSocSec = objSQLDR.GetString(6)
            strRsltLastExam = objSQLDR.GetString(7)

            'Display Results on the web form...
            lblMedRec.Text = strRsltMedRec
            lblRad.Text = strRsltRad
            lblPatient.Text = strRsltPatient
            lblPatient.ForeColor = Color.Black
            lblPatient.Font.Bold = False
            lblSex.Text = strRsltSex
            lblBirthDate.Text = strRsltBirthDate
            lblSocSec.Text = strRsltSocSec
            lblLastExam.Text = strRsltLastExam
            objSQLDR.Close() 'Close the DataReader

            lblPat.Visible = True  'Enable the labels on the form.
            lblBD.Visible = True
            lblSx.Visible = True
            lblSS.Visible = True
            lblMRNum.Visible = True
            lblRadNum.Visible = True
            lblLastEx.Visible = True

            objSQLCmd = New SqlCommand
            With objSQLCmd  'Query for the Procedures
                .Connection = objConnection
                .CommandType = CommandType.StoredProcedure
                .CommandText = "sp_GetProcByMedRec" 'Running this stored procedure
                .Parameters.Add("@MedRec", SqlDbType.Char).Value = strMed_Rec 'This is the parameter
            End With

            'Initialize the DataSet object and fill the adapter 
            objDataAdapter = New SqlDataAdapter(objSQLCmd)
            objDataSet = New DataSet
            objDataAdapter.Fill(objDataSet, "Procedures")
            Dim objDataView As DataView = objDataSet.Tables("Procedures").DefaultView
            grdPatient.Visible = True
            grdPatient.DataSource = objDataView
            grdPatient.DataBind()

            'Clean up 
            objConnection.Close()   'Close the SQL Connection
            objConnection.Dispose() 'Clears Memory
            objDataAdapter.Dispose()
            objDataSet.Dispose()

            txtGetMedRec.Text = ""
            txtGetLName.Text = ""
            txtGetFName.Text = ""
            Set_Focus(txtGetMedRec)
        End If
    End Sub

    'This Sub is used to set focus to the control that is passed in (Med Rec TextBox)
    'ASP.NET is server side based...you can't do a normal SetFocus...you have to use JavaScript to do client side controls
    Private Sub Set_Focus(ByVal oControl As Control)
        Dim strScript As String
        strScript = "<script language=javascript> document.all('" & oControl.ID & "').focus() </script>"
        RegisterStartupScript("ClientSideScript", strScript)
    End Sub


    'This Sub lets you hit enter on the MedRec TextBox and it will act like the FindPatient button was clicked
    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
        txtGetMedRec.Attributes.Add("onkeydown", String.Format("if(window.event.keyCode == 13) {{{0}.focus();}}", btnFindPatient.ClientID))
        txtGetLName.Attributes.Add("onkeydown", String.Format("if(window.event.keyCode == 13) {{{0}.focus();}}", btnFindPatient.ClientID))
        txtGetFName.Attributes.Add("onkeydown", String.Format("if(window.event.keyCode == 13) {{{0}.focus();}}", btnFindPatient.ClientID))
    End Sub
End Class

Yes, I am a Noob so don't feel bad for pointing out the mistakes!
TIA - Jeff