Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm facing a small problem and it would be great if someone can help me. Im having some textbox and requred field validator for each of these textboxes. I also have two buttons, one is a "login" button and the other is a "signup" button. In the click event of the signup button I have a Response.Redirect(Default5.aspx); for register Now my problem is that when I click the signup button the requred field validator's are getting activated. I need to activate them only when the "login" button is clicked


this is my code...
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

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

    protected void btnlogin_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=...........;Initial Catalog=EmployeeDB;Integrated Security=True");
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from information where Username=@Username and Password=@Password", con);
        cmd.Parameters.AddWithValue("@Username", TextBox1.Text);
        cmd.Parameters.AddWithValue("@Password", TextBox2.Text);
        SqlDataAdapter ad = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        ad.Fill(dt);
      
        if (dt.Rows.Count > 0)
        {           
                Session["Username"] = TextBox1.Text;

                Response.Redirect("Default3.aspx");            
        }

        else
        {
            Label3.Visible = true;
            Label3.Text = "Invalid Username&Password....!!!";
        }           
    }
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default5.aspx");
    }   
}
Posted
Updated 22-Mar-12 1:58am
v2

For the signup button set the property causevalidation to false.
 
Share this answer
 
Comments
rockpune 22-Mar-12 8:05am    
thank u brother
Hi,
Give the same validation group for validator and login button
Ex: ValidationGroup="login"
 
Share this answer
 
Hi,

Use Javascript validation instead of required field(server side) validators!
Using client side validation is better than server side validation!
 
Share this answer
 
Comments
rockpune 22-Mar-12 8:03am    
where it is?
Rahul Rajat Singh 22-Mar-12 8:17am    
I am confused, since when the required field validater is a server side validation.
Rahul Rajat Singh 22-Mar-12 8:19am    
The default behavior is client side validation only. If I disable the clientside then it will so that on server side.
You can place the required field validators in validation groups. This allow you to control which textboxes are validated on each button click. Please check out the site below.

http://msdn.microsoft.com/en-us/library/ms227424.aspx
 
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