Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8567979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:00:17+00:00 2026-06-11T18:00:17+00:00

Below is the code of my simple page’s submit button click. I am submitting

  • 0

Below is the code of my simple page’s submit button click. I am submitting an empty form but no server validation error messages are showing. What’s wrong with my code? When I click on submit, the page just turns blank and nothing happens. I am also unable to attach the debugger.

When I am building my website project, it is not showing any compilation error either. I don’t know what I am doing wrong.

 protected void btnSubmit_Click(object sender, EventArgs e)
        {
            // Need to Validate All Required Fields before redirecting to frmPersonalVerified.aspx
            bool blnFormIsValid = true;
            DateTime dtEndDate;
            DateTime dtStartDate;

            // Get Date because we have a value.
            dtEndDate = DateTime.Parse(txtEndDate.Text);

            // Get Date because we have a value.
            dtStartDate = DateTime.Parse(txtStartDate.Text);

            if (txtFirstName.Text.Trim() == "")
            {
                txtFirstName.BackColor = System.Drawing.Color.Yellow;
                lblError.Text = "Please enter first name.";
                blnFormIsValid = false;
            }
            else
            {
                lblError.Text = "";
                txtFirstName.BackColor = System.Drawing.Color.White;
                blnFormIsValid = true;
            }

            if (txtLastName.Text.Trim() == "")
            {
                txtLastName.BackColor = System.Drawing.Color.Yellow;
                lblError.Text = "Please enter last name.";
                blnFormIsValid = false;
            }
            else
            {
                lblError.Text = "";
                txtLastName.BackColor = System.Drawing.Color.White;
                blnFormIsValid = true;
            }
            if (txtPayRate.Text.Trim() == "")
            {
                txtPayRate.BackColor = System.Drawing.Color.Yellow;
                lblError.Text = "Please enter pay rate.";
                blnFormIsValid = false;
            }
            else
            {
                lblError.Text = "";
                txtPayRate.BackColor = System.Drawing.Color.White;
                blnFormIsValid = true;
            }
            if (txtStartDate.Text.Trim() == "")
            {
                txtStartDate.BackColor = System.Drawing.Color.Yellow;
                lblError.Text = "Please enter start date.";
                blnFormIsValid = false;
            }
            else
            {
                lblError.Text = "";
                txtStartDate.BackColor = System.Drawing.Color.White;
                blnFormIsValid = true;
            }
            if (txtEndDate.Text.Trim() == "")
            {
                txtEndDate.BackColor = System.Drawing.Color.Yellow;
                lblError.Text = "Please enter end date.";
                blnFormIsValid = false;
            }
            else
            {
                lblError.Text = "";
                txtEndDate.BackColor = System.Drawing.Color.White;
                blnFormIsValid = true;
            }

            // Compare Dates
            if (DateTime.Compare(dtStartDate, dtEndDate) >= 0)
            {
                txtStartDate.BackColor = System.Drawing.Color.Yellow;
                txtEndDate.BackColor = System.Drawing.Color.Yellow;
                lblError.Text = "Please make sure that start date is less than end date.";
                blnFormIsValid = false;
            }

            else
            {
                lblError.Text = "";
                txtStartDate.BackColor = System.Drawing.Color.White;
                txtEndDate.BackColor = System.Drawing.Color.White;
                blnFormIsValid = true;
            }

            if (blnFormIsValid == true)
            {
                //Assign a value to the session variable. 
                Session["FirstName"] = txtFirstName.Text;
                Session["LastName"] = txtLastName.Text;
                Session["PayRate"] = txtPayRate.Text;
                Session["StartDate"] = txtStartDate.Text;
                Session["EndDate"] = txtEndDate.Text;

                // Sends A Request from the Browser to the server.
                Response.Redirect("frmPersonalVerified.aspx");
            }
        }

Update

I just used .Equals(“”)… it’s not working. Still blank page is showing up

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:00:18+00:00Added an answer on June 11, 2026 at 6:00 pm

    Ignoring the fact that the correct way is to use ASP.NET’s built-in validation tools, the problem is that your program’s logic is broken.

    You’re using blnFormIsValid to store the validity of the form, however its value is meaningless because you’re assigning it without paying attention to previous state.

    If I submit your page’s form with these values…

    txtFirstName = "" // this is invalid
    txtLastName = "foo" // this is valid
    

    …then it will correctly fail the first validation and blnFormIsValid will be false, however your next check ignores the state of blnFormIsValid and sets it to true simply because txtLastName’s value is valid.

    This issue stems not from our lack of understanding or knowledge of ASP.NET, but basic programming and logic. A simple step-through or dry-run of your code would have revealed this.

    Below are my list of recommendations:

    Use ASP.NET Validation controls, like so:

    <input type="text" id="firstName" runat="server" />
    <asp:RequiredValidator runat="server" controlToValidate="firstName" />
    
    void Page_Load() {
        if( Page.IsPostBack) {
            Page.Validate();
            if( Page.IsValid ) {
                // that's all you have to do
            }
        }
    

    Don’t use Hungarian notation

    This is when you prefix an identifier with a tag that identifies its type, e.g. “blnFormIsValid” or “txtFirstName”. Just use “formIsValid” or “firstName”. Hungarian notation is only of use in environments where typing information is not provided by the editor.

    Don’t use foo == true

    … because the operation will evaluate to the same value as foo. In your case you should have if( formIsValid ) instead of if( formIsValid == true ). Avoiding unnecessary use of the == operator can help avoid cases where you accidentally use the = assignment operator instead of the == equality operator (and make your code more readable).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my code for a simple form in the create_session.php page. I am
I have a simple page (below) with a form. The form will submit if
The simple code block below can be served up in a static HTML page
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
I've got a simple question but it has got me confounded. The code below
I have a simple drop down box on a page with the below code:
I have a simple page that pops up a telerik radwindow on button click.
hopefully simple questions regarding Agle Toolkit. Currently with the below code getting Error in
The below code is very simple. I have a jQuery autocomplete bound to an
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.