我面临一个小问题,如果有人可以帮助我,那就太好了.我有一些文本框和每个这些文本框所需的字段验证器. [英] 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.

查看:52
本文介绍了我面临一个小问题,如果有人可以帮助我,那就太好了.我有一些文本框和每个这些文本框所需的字段验证器.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临着一个小问题,如果有人可以帮助我,那将是一个很好的选择.我有一些文本框和每个这些文本框所需的字段验证器.我也有两个按钮,一个是登录"按钮,另一个是注册"按钮.在注册按钮的点击事件中,我有一个Response.Redirect(Default5.aspx);进行注册现在,我的问题是,当我单击注册按钮时,所需的字段验证器就被激活了.我仅在单击登录"按钮时才需要激活它们


这是我的代码...

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...

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");
    }   
}

推荐答案

对于注册按钮,将属性causevalidation 设置为false.
For the signup button set the property causevalidation to false.



为验证器和登录按钮指定相同的验证组
例如:ValidationGroup ="login"
Hi,
Give the same validation group for validator and login button
Ex: ValidationGroup="login"




使用Javascript验证而不是必填字段(服务器端)验证器!
使用客户端验证比使用服务器端验证要好!
Hi,

Use Javascript validation instead of required field(server side) validators!
Using client side validation is better than server side validation!


这篇关于我面临一个小问题,如果有人可以帮助我,那就太好了.我有一些文本框和每个这些文本框所需的字段验证器.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆