Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with adding data from a form to a database

Status
Not open for further replies.

oas2009

Programmer
Feb 26, 2009
3
US
Code:
Private Sub btnSaveAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveAdd.Click
   Call AddJob()
   If invalid Then
      lblErrMsg.Text="Correct errors indicated below, then try again."
      lblErrMsg.ForeColor = System.Drawing.Color.Red
      lblErrMsg.Font.Bold = True
            Exit Sub
        End If
        If blnLenError Then
            MsgBox("Job Description cannot exceed 2000 characters.")
            Exit Sub
        Else
            Call ClearForm()
            ddState.SelectedItem.Text = "FL"
        End If
    End Sub

The above function is called when the user wants the job is added and the employer wants to add another. After the job is added, this function is called to clear the form and repost a clean & clear version of the AddJob.aspx

My problem is that after the user has selected Save & Go Back or Save & Add Another, the ClearForm , transfers the values of form fields to the values of the objects. After the form has cleared all the fields, the values are still located in the variables waiting to be added to the database. However, during the postback, the form comes back clear and the information stored in the form variables are cleared without being added to the database
 
this line is an issue
Code:
MsgBox("Job Description cannot exceed 2000 characters.")
as this is a webform. message box would appear on the server and cause problems. this may work in development because your dev box is both the server and client.

if you want the form to clear after you're finished, issue a redirect back to the form. this will clear postbacks, viewstate, etc.
Code:
bool valid = save_job();
if(valid)
   response.redirect("mywebform.aspx");
else
   display errors.
if the values aren't saving to the database then the problem is probably with AddJob()

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks, I'll definately check that out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top