not displaying the popup message

Hi there i have an c# web form application where i have a few text boxes and a gridview underneath the teaxtbox. but some of the textboxes are required field. so if the user forgets to enter those and directly tries to input data in the gridview i make a check to see if any of the required field above is empty if it is i pop a message box saying 'Please Make Sure The above Required fields are filled' the problem is it runs through the code with out popping the message and continues on to the try catch condition

here is the code

  protected void PiceCode(object sender, EventArgs e)
        {
            Checkifabovefieldsarenotempty(); <----  [b]this is the method that checks for empty controls, the problem is it runs through the code with out popping the message and continues on to the try catch condition[/b]
              try
              {
            SqlConnection sqlcon = new SqlConnection(con);
            string query = "Select Description FROM [Item Master] Where Item = \'" + ((TextBox)GridView1.HeaderRow.FindControl("TextBox3")).Text + "\'";
            SqlCommand com = new SqlCommand(query, sqlcon);
            sqlcon.Open();
            var value = (com.ExecuteScalar());
            ((TextBox)GridView1.HeaderRow.FindControl("TextBox4")).Text = value.ToString().Trim();
            sqlcon.Close();
              if (value.ToString().Length > 0)
            {

            }
            else
            {
                string script = "alert(\"the product code entered was not found\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                      "ServerControlScript", script, true);
            }
            }
            catch (Exception ex)
            {

                string script = "alert(" + ex.Message.ToString() + ");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                      "ServerControlScript", script, true);
            }
}

Open in new window


 public void Checkifabovefieldsarenotempty()
        {
            if (LineValues.SelectedIndex == 0 || todaydate.Text == string.Empty || shiftvalues.SelectedIndex == 0 || staffused.Text == string.Empty)
            {                
                string script = "alert(\"Please Make Sure The above Required fields are filled\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
               "ServerControlScript", script, true);
            }
        }

Open in new window

Aravind RanganathanWindows Application DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
If you're doing a test, then can change Checkifabovefieldsarenotempty() to public bool and returning an appropriate value on validation.  Then in your code:

if (Checkifabovefieldsarenotempty())
{
    //if returned true
}
else
{
  //if returned false
}

Open in new window


Honestly though, I have a much easier time doing that validation in JavaScript on the page before submitting to the server.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aravind RanganathanWindows Application DeveloperAuthor Commented:
thanks buddy
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.