Community discussion forum

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

  • 1 year 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
  • 0 month
    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
  • 0 month
    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
  • 0 month
  • 0 month
    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
  • 0 month
    try to place javascript before
  • 0 month
    befor <asp marker

Post a reply

Enter your message below

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

We'd love to hear what you think! Submit ideas or give us feedback