How can I execute server-side function using asp.net Ontextchanged orJavascript onchange?

asp.net , vb.net , javascript Pomona, United States
  • 12 years ago
    I try to have my textbox in asp.net so what like instant search. While use input char by char, server-side method can seek database is there is matching record. I done many research. People are saying different things like using javascript onchange and doing postback, but I not good in javascript. And, I tried javascript; it doesn't work out. Currently, If I take out javascript code, the function working properly only under press enter key or textbox lost focus. I just want it simple and works, no security issue or other stuff are concern. Please Advise The following as my current code. Protected Sub txtStudentID_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtStudentID.TextChanged Dim strStudentID As String Dim db As DataConnection Dim query As String Dim Data As ArrayList Data = New ArrayList() db = New DataConnection strStudentID = txtStudentID.Text If strStudentID <> "" Then query = "SELECT LastName, FirstName FROM Student WHERE StudentID = '" + strStudentID + "'" Data = db.SelectData("Student", query) If Data.Count > 1 Then lblStudent.Text = "More than one student found." ElseIf Data.Count = 1 Then lblStudent.Text = Data(0) Else lblStudent.Text = "Invaild index." End If End If End Sub
  • 12 years ago
    um, can you post more of your code, as html, as js? for now just forget about server side, if it was wrong there, it would not throw error in js.
    Regards, Matt
  • 12 years ago
    Here is my code. Protected Sub txtStudentID_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtStudentID.TextChanged Dim strStudentID As String Dim db As DataConnection Dim query As String Dim Data As ArrayList Data = New ArrayList() db = New DataConnection strStudentID = txtStudentID.Text If strStudentID <> "" Then query = "SELECT LastName, FirstName FROM Student WHERE StudentID = '" + strStudentID + "'" Data = db.SelectData("Student", query) If Data.Count > 1 Then lblStudent.Text = "More than one student found." ElseIf Data.Count = 1 Then lblStudent.Text = Data(0) Else lblStudent.Text = "Invaild index." End If End If End Sub
  • 12 years ago
  • 12 years ago
    Sorry I don't quite sure how to use this form so there is mutiple error post. Protected Sub txtStudentID_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtStudentID.TextChanged Dim strStudentID As String Dim db As DataConnection Dim query As String Dim Data As ArrayList Data = New ArrayList() db = New DataConnection strStudentID = txtStudentID.Text If strStudentID <> "" Then query = "SELECT LastName, FirstName FROM Student WHERE StudentID = '" + strStudentID + "'" Data = db.SelectData("Student", query) If Data.Count > 1 Then lblStudent.Text = "More than one student found." ElseIf Data.Count = 1 Then lblStudent.Text = Data(0) Else lblStudent.Text = "Invaild index." End If End If End Sub
  • 12 years ago
    try to place javascript before
  • 12 years ago
    befor <asp marker

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - Rick Osborne