Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am validating two text boxes in asp.net page. if the validation is correct, then the page auto directs to a new page. if the validation is not correct, then the system keeps on the same page with prompt to the user. if the validation is correct then how to navigate to next page. any code clue using c#

What I have tried:

C#
protected void Button1_Click(object sender, EventArgs e)
{
    if (TextBox1.Text != "india")
    {
       if (TextBox3.Text != "50000")
       {
       }
    }

    Response.Write("alert('Not eligible')");

    else {
          // what i have to write here 
      }
Posted
Updated 16-Jan-17 23:24pm
v3
Comments
F-ES Sitecore 17-Jan-17 5:26am    
This code is invalid, it won't even compile. If an "else" isn't working then there is a problem with your code as your code can't be what is posted above. To give you help we'll need to see the actual code, but Solution 1 is what you need, I suspect you are maybe placing your else in the wrong place.
Member 12950401 17-Jan-17 5:31am    
dear sir

below is complete code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class salaried : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{


if (TextBox1.Text != "india")
{

if (TextBox3.Text != "50000")
{
}
}

Response.Write("alert('Not eligible')");
else
{
Response.Redirect("saldetail.aspx");
}



}
}
F-ES Sitecore 17-Jan-17 5:50am    
That code won't compile. You need something like

if (TextBox1.Text != "india" || TextBox3.Text != "50000")
{
Response.Write("alert('Not eligible')");
}
else
{
Response.Redirect("saldetail.aspx");
}
Member 12950401 17-Jan-17 6:12am    
its working....thank you sir for your help...i am writing remaining code..i will post the further questions here.
Member 12950401 17-Jan-17 6:27am    
dear sir

i want to add another validation on another text box. the validation is " the age entered by the user should be between 20 and 60". how to cater this ? i am trying below code but it is not working

if (age > 22 && age < 60)

1 solution

You can use following
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "india")
{
  if (TextBox3.Text != "50000")
  {
   Response.Write("alert('Not eligible')");
  }
}
else {
   Response.Redirect("http://www.microsoft.com");
}
 
Share this answer
 
v2
Comments
Member 12950401 17-Jan-17 5:13am    
dear sunasara

else is not working. i have tried

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