We help IT Professionals succeed at work.
Get Started

Populate textbox from database using ajax

TonyReba asked
Last Modified: 2012-05-11
Hi, I have the following scenario: An SQL 2000 database with a table containing the columns UserID and UserName. A webpage with TextBox1 and TextBox2.

I need to use  AJAX  or Jquey to accomplish the following: When I type the patient ID  in txtPatientId textbox and press the Tab key, txtMRN will populate with the corresponding MRN number.

How do implement this this is what I  have but is not working.

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string GetDynamicContent(string contextKey)
        string outputString = string.Empty;
        string strConn = ConfigurationManager.ConnectionStrings[""].ConnectionString;
        SqlConnection dbConnection = new SqlConnection(strConn);
        SqlCommand dbCommand = new SqlCommand
        ("SELECT TPM300_PAT_VISIT.vst_ext_id AS VisitID,  FROM TABLE ......"

  return outputString;

Open in new window

<asp:TextBox ID="txtMRN" runat="server" MaxLength="15"></asp:TextBox>
            <asp:DynamicPopulateExtender ID="txtMRN_DynamicPopulateExtender" runat="server" 
                Enabled="True" PopulateTriggerControlID="btn_Go" ServiceMethod="GetDynamicContent" 
                TargetControlID="txtMRN" ContextKey="txtPatientId">

Open in new window

Watch Question
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE