使用asp.net填充字段后重定向到下一页? [英] redirect to next page after fill fields using asp.net?

查看:89
本文介绍了使用asp.net填充字段后重定向到下一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

面临小问题



这里一旦填满所有字段,导航到另一个页面意味着索引页面到index2在这里我们写代码redirect()方法请回复我



或任何错误请回复我

  public   partial   class 索引:系统。 Web.UI.Page 
{
protected void Page_Load( object sender,EventArgs e)
{

}
private < span class =code-keyword> void Redirect()

{
SqlConnection con = new SqlConnection( ConfigurationManager.ConnectionStrings [ ConnectionString]。ConnectionString);
SqlCommand cmd = new SqlCommand( select *来自SignUpTable,其中Username = @ Username and Password = @ Password,con);
cmd.Parameters.AddWithValue( @ Username,txtEmailAddress.Text);
cmd.Parameters.AddWithValue( @ Password,txtPassword.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

if (dt.Rows.Count > 0
{
DataRow dr = dt.Rows [ 0 ];
会话[ 用户名] = dr [ 用户名]。ToString();
Response.Redirect( Index2.aspx);
}
}
受保护 void btnSignup_Click( object sender,EventArgs e)
{
int userId = 0 ;
string constr = ConfigurationManager.ConnectionStrings [ 的ConnectionString]的ConnectionString。
使用(SqlConnection con = new SqlConnection(constr))
{
使用(SqlCommand cmd = new SqlCommand( SP_SignUpTable))
{
使用(SqlDataAdapter sda = < span class =code-keyword> new
SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue( @ FirstName ,txtFirstName.Text.Trim());
cmd.Parameters.AddWithValue(
@LastName ,txtLastName.Text.Trim());
cmd.Parameters.AddWithValue(
@Username ,txtEmailAddress.Text.Trim());
cmd.Parameters.AddWithValue(
@Password ,txtCreatePassword.Text.Trim());
cmd.Parameters.AddWithValue(
@ConfirmPassword ,txtConfirmPassword.Text.Trim());
cmd.Parameters.AddWithValue(
@MobileNumber ,txtMobilenumb er.Text.Trim());
cmd.Parameters.AddWithValue(
@Area ,txtResearch.Text.Trim() );
cmd.Parameters.AddWithValue(
@DateOfBirth ,txtDOB.Text.Trim() );
cmd.Parameters.AddWithValue(
@Gender ,RadioButtonList1.Text.ToString() );
cmd.Connection = con;
con.Open();
userId = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
}
string message = string.Empty;
switch(userId)
{
case -1:
message =
用户名已经存在。\\ n请选择其他用户名。 ;
休息;
case -2:
message =
已提供电子邮件地址。 ;
休息;
}

ClientScript.RegisterStartupScript(GetType(),
alert alert(' + message +'); ,true);
}
}
private void Clear()
{
txtFirstName.Text = txtLastName.Text = txtEmailAddress.Text = txtPassword.Text = txtConfirmPassword.Text = txtMobilenumber。 Text = txtResearch.Text =
;
}
protected void btnLogin_Click(object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [
ConnectionString ]。ConnectionString);
con.Open();
SqlCommand cmd =新的SqlCommand(
选择 * 来自 SignUpTable 其中用户名= @用户名和密码= @密码 ,con);
cmd.Parameters.AddWithValue(
@Username ,txtEmail.Text);
cmd.Parameters.AddWithValue(
@Password ,txtPassword.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

if(dt.Rows.Count> 0)
{
DataRow dr = dt.Rows [0];
会话[
用户名 ] = dr [用户名 ]。ToString();
Response.Redirect(
主页.aspx );
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(),
validation < script launguage =' javascript' > alert(' 无效的电子邮件和密码'< / 脚本 > );
}
}
}







已添加标签。

[/编辑]

解决方案

  if (dt.Rows.Count >   0 
{
DataRow dr = dt.Rows [ 0 ];
会话[ 用户名] = dr [ 用户名]。ToString();
Response.Redirect( Index2.aspx);
}



这里需要注意的事情。



  1. 调试查看是否返回任何行。
  2. 查看 Index2.aspx 是否与此页面位于同一目录。

Dear All,
am facing small issue

here once fill all fields after that navigate to another page means index page to index2 page here where we write code redirect() method please reply me

or any mistakes please reply me

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

{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    SqlCommand cmd = new SqlCommand("select * from SignUpTable where Username=@Username and Password=@Password", con);
    cmd.Parameters.AddWithValue("@Username", txtEmailAddress.Text);
    cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);

    if (dt.Rows.Count > 0)
    {
        DataRow dr = dt.Rows[0];
        Session["Username"] = dr["Username"].ToString();
        Response.Redirect("Index2.aspx");
    }
}
protected void btnSignup_Click(object sender, EventArgs e)
{
    int userId = 0;
    string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SP_SignUpTable"))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@FirstName"", txtFirstName.Text.Trim());
                cmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim());
                cmd.Parameters.AddWithValue("@Username",txtEmailAddress.Text.Trim());
                cmd.Parameters.AddWithValue("@Password", txtCreatePassword.Text.Trim());
                cmd.Parameters.AddWithValue("@ConfirmPassword", txtConfirmPassword.Text.Trim());
                cmd.Parameters.AddWithValue("@MobileNumber", txtMobilenumber.Text.Trim());
                cmd.Parameters.AddWithValue("@Area", txtResearch.Text.Trim());
                cmd.Parameters.AddWithValue("@DateOfBirth", txtDOB.Text.Trim());
                cmd.Parameters.AddWithValue("@Gender", RadioButtonList1.Text.ToString());
                cmd.Connection = con;
                con.Open();
                userId = Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();
            }
        }
        string message = string.Empty;
        switch (userId)
        {
            case -1:
                message = "Username already exists.\\n Please choose a different username.";
                break;
            case -2:
                message = "Supplied Email address has already been used.";
                break;
        }

        ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
    }
}
private void Clear()
{
    txtFirstName.Text = txtLastName.Text = txtEmailAddress.Text = txtPassword.Text = txtConfirmPassword.Text = txtMobilenumber.Text = txtResearch.Text = " ";
}
protected void btnLogin_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("select * from SignUpTable where Username=@Username and Password=@Password", con);
    cmd.Parameters.AddWithValue("@Username", txtEmail.Text);
    cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);

    if (dt.Rows.Count > 0)
    {
        DataRow dr = dt.Rows[0];
        Session["Username"] = dr["Username"].ToString();
        Response.Redirect("Home Page.aspx");
    }
    else
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script launguage='javascript'>alert('Invalid Email and Password')</script>");
    }
}
}



[Edit member="Tadit"]
Added pre tags.
[/Edit]

解决方案

if (dt.Rows.Count > 0)
{
    DataRow dr = dt.Rows[0];
    Session["Username"] = dr["Username"].ToString();
    Response.Redirect("Index2.aspx");
}


Couple of things to note here.


  1. Debug and see whether any Rows are returned or not.
  2. See if Index2.aspx is in the same directory as this Page.


这篇关于使用asp.net填充字段后重定向到下一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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