Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am validating page in code behind using if-else statement. i didn't need asp.net validator for this.
If else statement working fine. but the problem is that page is still submitting when it execute else condition.
I want when i click save button and when execution reach in else condition , the page set to invalid. or it i need to prevent page when code is in else statement



C#
EntityMpdb1 obentitympdb1 = new EntityMpdb1();
            BalLoginTable obupdatepensioner = new BalLoginTable();
            DataSet dspensionrecord = new DataSet();
            BalLoginTable obbalpensionrecord = new BalLoginTable();
            try
            {
                obentitympdb1.Authority_No = Txtauthorityno.Text;
                Match match = Regex.Match(Txtauthoritydate.Text, @"^([1-9]|0[1-9]|1[0-2])[- / .]([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])[- / .](1[9][0-9][0-9]|2[0][0-9][0-9]|3[0][0-9][0-9])$");
                if (match.Success)
                {
                    string val = match.Groups[1].Value;
                     
                }
                else
                {

                    spstartdate.InnerText = "Please enter correct date";                 
 
                }
  obupdatepensioner.updatepensionderdetail(obentitympdb1);
}
catch
{
}
Posted
Updated 1-Apr-12 20:31pm
v3
Comments
Prasad_Kulkarni 2-Apr-12 2:18am    
can you post code, what you have tried..
Sebastian T Xavier 2-Apr-12 2:18am    
can you submit your code?

Use this code in else part:
HTML
ClientScript.RegisterStartupScript("msg", "alert('Enter valid UserName and Password.');", true);
            txtUserName.Text = "";
            txtPassword.Text = "";
            txtUserName.Focus();
 
Share this answer
 
You can try the following too....

Throw an exception from else, and handle it using exception handling....

Regards
Sebatian
 
Share this answer
 

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