Click here to Skip to main content
15,887,930 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello all,

my friend tried explaining to me how my error message is being overwritten and i tried making a custom variable to hold the message but i am still getting the same error.
Only my last validation works on these textboxes and all my ones before it are blank.

Could someone explain or help me come up with a good solution for these?

here is what i have been working on.

Also the beginning message

-missing information has not been added to any of my errors although i did a += so i thought that it would be added.

C#
bool accountFlag = false;
string message = "";   //i just added this variable ...
 lblAcctMsg.Text = "Missing Information";

if (this.txtAccountName.Text == "")
            {
                message = " - AccountName";
                lblAcctMsg.Text += message; //" - AccountName";
                lblAccountnameErr.Visible = true;
                accountFlag = true;
            }
            else
            {
                message = "";
                lblAccountnameErr.Visible = false;
                lblAcctMsg.Text = "" + message;
            }
            //primary account id textbox
            if (this.txtPrimaryAct.Text == "")
            {
                lblAcctMsg.Text += " - Primary AccountName";
                lblPrimaryAccountIDError.Visible = true;
                accountFlag = true;
            }
            else
            {
                lblPrimaryAccountIDError.Visible = false;
                lblAcctMsg.Text = "";
            }
try
            {
                double d = Convert.ToDouble(txtVolatility.Text);
                if (this.txtVolatility.Text == "")
                {
                    lblAcctMsg.Text = " - Volatility";
                    lblVolatilityError.Visible = true;
                    accountFlag = true;
                }
                else
                {
                    lblVolatilityError.Visible = false;
                    lblAcctMsg.Text = "";
                }
            }
            catch
            {
                lblAcctMsg.Text = " - Volatility";
                lblVolatilityError.Visible = true;
                accountFlag = true;
            }
            if (accountFlag)
                return;
Posted

1 solution

Are you validating on post back?
if so then you can use hidden fields to store the message for you and assign them accordingly.
 
Share this answer
 
Comments
Sascha Lefèvre 2-Apr-15 17:17pm    
He's talking about Windows Forms
TheBigBearNow 2-Apr-15 17:34pm    
nope im using C# not asp.net

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900