Answered by:
Posting result to a webpage

Question
-
User756459238 posted
I have a web page which allows a user to enter a Student ID. When the user enters the ID then clicks a button to lookup the details of their account. The information is looked up from a database table. I want the results to post back to the page. What I have found is that the page post back seems to occur before the ID information is looked up. If the user then re-enters the student id a second time and clicks the lookup button again , then the results post in the web page form. How do I get the page to post the results of the lookup after the first lookup. Thanks
Dennis
Saturday, November 16, 2019 2:50 AM
Answers
-
User756459238 posted
My apologies for your time. I had wrapped the student info portion of this page in a formview control. The initial mode was InsertItemTemplate, but I did not create a EditItemTemplate after the lookup. Problem solved.
Thanks for your time.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, November 19, 2019 2:02 AM
All replies
-
User475983607 posted
You wrote a bug. We can't provide debugging support without the code.
Saturday, November 16, 2019 12:14 PM -
User756459238 posted
Protected Sub IDLookupButton_Click(ByVal sender As Object, ByVal e As EventArgs)
' This module will attempt to lookup the student record from the table _FDMembers
' If a record is found, that information will be placed in the Web page.
' The user can only accept the information or clear it.
' The student cannot update thier information in this portion of the program,
' since it is unsecured, except for the email at the bottom
Try
Dim MessageLabel As New Label
MessageLabel = CType(FormView1.FindControl("Messagelabel"), Label)Dim ID As New TextBox
ID = CType(FormView1.FindControl("IDtextbox"), TextBox)Dim StudentID As String
StudentID = ID.Text.ToStringDim Orgdropdown As New DropDownList
Orgdropdown = CType(FormView1.FindControl("OrgDropDownList"), DropDownList)Dim OrgPlaceholder As New PlaceHolder
OrgPlaceholder = CType(FormView1.FindControl("OrgPlaceholder"), PlaceHolder)Dim Orgtextbox As New TextBox
Orgtextbox = CType(FormView1.FindControl("Orgtextbox"), TextBox)Dim FirstTextbox As New TextBox
FirstTextbox = CType(FormView1.FindControl("Firsttextbox"), TextBox)Dim LastTextbox As New TextBox
LastTextbox = CType(FormView1.FindControl("Lasttextbox"), TextBox)Dim AddressTextbox As New TextBox
AddressTextbox = CType(FormView1.FindControl("Addresstextbox"), TextBox)Dim CityTextbox As New TextBox
CityTextbox = CType(FormView1.FindControl("Citytextbox"), TextBox)Dim StateTextbox As New TextBox
StateTextbox = CType(FormView1.FindControl("Statetextbox"), TextBox)Dim ZipTextBox As New TextBox
ZipTextBox = CType(FormView1.FindControl("ZipTextbox"), TextBox)Dim ContactNumberTextbox As New TextBox
ContactNumberTextbox = CType(FormView1.FindControl("ContactNumbertextbox"), TextBox)Dim DOBTextbox As New TextBox
DOBTextbox = CType(FormView1.FindControl("DOBtextbox"), TextBox)Dim EMailTextbox As New TextBox
EMailTextbox = CType(FormView1.FindControl("EMailtextbox"), TextBox)Dim ShowRegisteredbutton As Button
ShowRegisteredbutton = CType(FormView1.FindControl("ShowRegisteredbutton"), Button)Dim DBConnection As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|vwd.mdb")
Dim SelectString As StringDim DBConnection2 As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|StudentInfo.mdb")
Session("OrgID") = Nothing
Session("OrgName") = Nothing
Orgdropdown.SelectedValue = "00000"
FirstTextbox.Text = Nothing
LastTextbox.Text = Nothing
DOBTextbox.Text = Nothing
AddressTextbox.Text = Nothing
CityTextbox.Text = Nothing
StateTextbox.Text = Nothing
ZipTextBox.Text = Nothing
ContactNumberTextbox.Text = Nothing
EMailTextbox.Text = Nothing
Session("StudentID") = StudentID
Session("IDtextbox") = ID.Text.ToString' Lookup ID in FDMembers table, if found, autofill registration form
DBConnection.Open()
SelectString = "SELECT * FROM [_FDMembers] Where [StudentID] = ?"
Dim DBCommand As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand(SelectString, DBConnection)
DBCommand.Parameters.Add("@p1", Data.OleDb.OleDbType.VarChar).Value = StudentID
Dim DBReader As Data.OleDb.OleDbDataReader = DBCommand.ExecuteReader(Data.CommandBehavior.Default)
If DBReader.HasRows Then
While DBReader.Read()
If DBReader("OrgID") = "99999" Then
' Other Org
OrgPlaceholder.Visible = True
Orgtextbox.Text = DBReader("Organization")
Else
Orgtextbox.Text = Nothing
OrgPlaceholder.Visible = False
End If
Orgdropdown.SelectedValue = DBReader("OrgID").ToString
Session("OrgID") = DBReader("OrgID").ToString
Session("OrgName") = DBReader("Organization").ToString
Orgtextbox.Text = Session("OrgName")
FirstTextbox.Text = DBReader("FirstName").ToString
Session("Firstname") = DBReader("FirstName").ToString
LastTextbox.Text = DBReader("LastName").ToString
Session("Lastname") = DBReader("LastName").ToString
DOBTextbox.Text = FormatDateTime(DBReader("DOB"), DateFormat.ShortDate)
Session("DOB") = FormatDateTime(DBReader("DOB"), DateFormat.ShortDate)
AddressTextbox.Text = DBReader("HomeAddress").ToString
Session("Address") = DBReader("HomeAddress").ToString
CityTextbox.Text = DBReader("HomeCity").ToString
Session("City") = DBReader("HomeCity").ToString
StateTextbox.Text = DBReader("HomeState").ToString
Session("State") = DBReader("HomeState").ToString
ZipTextBox.Text = DBReader("HomeZip").ToString
Session("Zip") = DBReader("HomeZip").ToString
ContactNumberTextbox.Text = DBReader("ContactNumber").ToString
Session("Contact") = DBReader("ContactNumber").ToString
EMailTextbox.Text = DBReader("EMail").ToString
Session("Email") = DBReader("EMail").ToString
MessageLabel.Text = "Verify the information below refers to you. Update as needed, then click the Register button."
MessageLabel.Visible = True
Orgdropdown.Enabled = True
FirstTextbox.ReadOnly = True
LastTextbox.ReadOnly = True
DOBTextbox.ReadOnly = True
AddressTextbox.Enabled = True
CityTextbox.Enabled = True
StateTextbox.Enabled = True
ZipTextBox.Enabled = True
ContactNumberTextbox.Enabled = True
If Not Session("OrgName") = "" Then
ShowRegisteredbutton.Visible = True
End If
End WhileElse
' StudentID not foundMessageLabel.Text = "No match found for the ID entered. " _
& "Select HELP button for more info on the StudentID. After filling-in all text boxes, select the REGISTER button."
MessageLabel.Visible = True
' Hide the button which hides the ID info message if its visible
Dim InfoPlaceholder As New PlaceHolder
InfoPlaceholder = CType(FormView1.FindControl("InfoPlaceHolder"), PlaceHolder)
InfoPlaceholder.Visible = True
End If
'-- Close the data reader and database connection
DBReader.Close()
DBConnection.Close()Catch ex As Exception
'MsgBox(ex.ToString)
Dim Errstr As String = ex.Message.ToString()
' Send an email to the programmer so this error can be resolved.
Dim ErrMsg As String
ErrMsg = "Error in Course Register in IDLookupButton_Click. The Student " & Session("StudentID") & ":"
ErrMsg = ErrMsg & " registering for the Course "
ErrMsg = ErrMsg & Session("CourseName") & " caused an exception error on " & Now() & "."
ErrMsg = ErrMsg & vbCrLf & Errstr
NotifyProgrammerOfError(ErrMsg)
End TryEnd Sub
Saturday, November 16, 2019 4:11 PM -
User756459238 posted
I posted the code but it needs moderator approval before it will post.
The page this code belongs to displays a Course that a student selected to attend which will be taught by the NE State Fire Marshal Training Division. When the user selects a course this page displays the course info on the right side of the page and the student registration info on the left. If the student has prev registered for a course, their info can be looked--up, which is what the code I posted performs. If the student is not in the system, they can enter their info and click the Register button. If the Student info is found, then that data is displayed and the user can then click the Register button to complete the registration. The Registration page can be viewed after you click the Registration button for any course at this link https://nebraskasfmtd.ne.gov/Courses/Courses_Avail.aspx
Thanks
Dennis
Saturday, November 16, 2019 4:24 PM -
User288213138 posted
Hi DennisMiller,
What I have found is that the page post back seems to occur before the ID information is looked upFrom your code, i can't reproduce your question, because of only a click event in your code.
Please post more details code about your question. how did you set you postback event?
Best regards,
Sam
Monday, November 18, 2019 11:42 AM -
User753101303 posted
Hi,
"before the ID information is looked up"
It seems your lookup button does a postback. If you mean you have another postback prior to that could it be that you have an AutoPostBak on this TextBox input field for example? Try F12 Network which should help to understand when exactly and how his extra postback is triggered.
IMO don't look at your code too early. Use rather debugging tools to see what happens exactly and then you can better narrow down where to look to see what causes the exact behavior you see.
Monday, November 18, 2019 12:02 PM -
User756459238 posted
Thanks for the feedback
The postback event does nothing on a postback but if it is not a post back I set the OrgId to (Select an Organization)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If not Page.IsPostBack Then
' This is the first time the page is loaded, so set OrgID to (Select)
Dim OrgDropDownList As New DropDownList
OrgDropDownList = CType(FormView1.FindControl("OrgDropDownList"), DropDownList)OrgDropDownList.SelectedValue = "00000"
End IfTuesday, November 19, 2019 1:19 AM -
User756459238 posted
My apologies for your time. I had wrapped the student info portion of this page in a formview control. The initial mode was InsertItemTemplate, but I did not create a EditItemTemplate after the lookup. Problem solved.
Thanks for your time.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, November 19, 2019 2:02 AM