Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code when i want click linkbutton to register new i want to open register form

iam trying but not getting 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
{


SqlConnection con = new SqlConnection("..............;Initial Catalog=EmployeeDB;Integrated Security=True");


protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnlogin_Click(object sender, EventArgs e)
{
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 LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default5.aspx");
}
}
Posted
Comments
Sergey Alexandrovich Kryukov 22-Mar-12 3:09am    
"Not getting this..." is not informative. Please explain the problem properly. Format the code; hard to read, honestly...
--SA
rockpune 22-Mar-12 3:16am    
i create register form in login form when i click on linkbutton signup button it was not opening register form how can i do that
hiren soni 22-Mar-12 3:14am    
can you please write your question first in details and then a sample code please?
rockpune 22-Mar-12 3:16am    
i create register form in login form when i click on linkbutton signup button it was not opening register form how can i do that

1 solution

hi ,
C#
protected void btnlogin_Click(object sender, EventArgs e)
    {
//stored proc is prefered .
      string statment =string.Format("select * from information where Username={0} and Password={1}",TextBox1.Text  ,TextBox2.Text)
      SqlCommand cmd = new SqlCommand(statment, con);
      cmd.CommandType = CommandType.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....!!!";

        }

    }
 
Share this answer
 
Comments
rockpune 22-Mar-12 3:20am    
i create register form in login form when i click on linkbutton signup button it was not opening register form how can i do that
Mohamed Mitwalli 22-Mar-12 3:52am    
so u need to navigate to register form ?
if it is use this
Response.Redirect("register.aspx");

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