We help IT Professionals succeed at work.

Expiry of passport

sana khan
sana khan asked
on
150 Views
Last Modified: 2017-05-15
Code is working fine but to display the error for 6 months expiry we have to fill all the fields in the form.
so is there any way to show error as soon as the user enter wrong date in field.
 
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // Calling function
        passportexpiry();
        passport1expiry();
        visaexpiry();

        //Insert into database
        if ((lblError.Text == "") && (lblError2.Text == "") && (lblError3.Text == ""))
        {
            string QueryString = "insert into VisaApp values('" + txtFirstName.Text + "','" + txtMiddleName.Text + "','" + txtLastName.Text + "','" + ddlCurrentNationality.Text + "','" + ddlPreviousNationality.Text + "','" + txtDateOfBirth.Text + "','" + txtPlaceOfBirth.Text + "','" + ddlCountryBirth.SelectedItem.Text + "','" + txtPassportNo.Text + "','" + txtPassportIssueDate.Text + "','" + txtPassportExpiryDate.Text + "','" + txtPassportPlaceofIssue.Text + "','" + ddlPassportCountryIssue.SelectedItem.Text + "','" + ddlCurrentVisaStatus.SelectedItem.Text + "','" + txtVisaExpiryDate.Text + "','" + txtFatherName.Text + "','" + txtMotherName.Text + "','" + ddlMaritalStatus.SelectedItem.Text + "','" + ddlReligion.SelectedValue + "','" + txtEducationalQualification.Text + "','" + txtLanguageSpoken.Text + "','" + txtPermanentNativeAddress.Text + "','" + txtPermanentNativeCity.Text + "','" + txtPermanentNativePOBox.Text + "','" + ddlPermanentCountry.SelectedItem.Text + "','" + txtSponsorName.Text + "','" + ddlSponsorRelationship.Text + "','" + ddlNationality.Text + "','" + txtPassportNumber.Text + "','" + txtPassportDateofIssue.Text + "','" + txtPassportDateofExpiry.Text + "','" + txtVisaFileNumber.Text + "','" + txtSponsorVisaExpiryDate.Text + "','" + txtPhoneNo.Text + "','" + txtAddress.Text + "','" + txtPoBox.Text + "','" + ddlEmirate.Text + "')";
            SqlConnection con = new SqlConnection(cs);
            SqlCommand cmd = new SqlCommand(QueryString, con);
            con.Open();
            cmd.ExecuteNonQuery();
            //Response.Write("Data Inserted");
            Response.Write("<script>alert('Form has been successfully Submtted')</script>");
            con.Close();
        }
    }


        // Validation for passport expiry(6 months)
    private void passportexpiry()
    {
        var value = DateTime.Now;
        // var val = DateTime.Parse(value);
        var val = DateTime.Parse(txtPassportExpiryDate.Text);

        var diffindays = val - value;

        if (diffindays.Days >= (6 * 31))
        {
            lblError.Text = "";
        }

        else
        {
            lblError.Text = "Must have atleast 6 months validity";
        }

    }

    // Validation for passport expiry(6 months)
    private void passport1expiry()
    {
        var value = DateTime.Now;
        // var val = DateTime.Parse(value);
        var val = DateTime.Parse(txtPassportDateofExpiry.Text);

        var diffindays = val - value;

        if (diffindays.Days >= (6 * 31))
        {        
            lblError2.Text = ""; 
        }

        else
        {         
            lblError2.Text = "Must have atleast 6 months validity";
        }
    }

    // Validation for visa expiry(6 months)
    private void visaexpiry()
    {
        var value = DateTime.Now;
        // var val = DateTime.Parse(value);
        var val = DateTime.Parse(txtSponsorVisaExpiryDate.Text);

        var diffindays = val - value;

        if (diffindays.Days >= (6 * 31))
        {
            lblError3.Text = "";
        }

        else
        {
            lblError3.Text = "Must have atleast 6 months validity";
        }
    }

Open in new window

Comment
Watch Question

Author

Commented:
Like the one we are using in asp.net for a field that should enter only numbers for example as soon as we enter any letter in po box field it  gives error to enter only numbers exactly that way i want for passport expiry as soon as user enter the date less than  6 months it must give error that...you must have atleast 6 months validity......
Please help
Pravin AsarPrincipal Systems Engineer
CERTIFIED EXPERT
Top Expert 2005

Commented:
For date fields you could use datepicker. Which take care of validations of date values.
Pravin AsarPrincipal Systems Engineer
CERTIFIED EXPERT
Top Expert 2005

Commented:
Look for datepicker example

https://jsfiddle.net/nkvpsumq/2/

Author

Commented:
I have tried using javascript also but not working in asp so i tried this way

Author

Commented:
Can anyone please help me for this
Asp.Net Developer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Vishal TankariyaAsp.Net Developer

Commented:
It is working with bootstrap jquery.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.