Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"
- AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
- <asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
- Runat="Server">
- <head>
- <link href="Style/Register.css" rel="stylesheet" />
- </head>
- <body>
- <div class="login-page">
- <div class="form">
- <form class="register-form">
- <input id="username" type="text" placeholder="Username" Runat="Server"/>
- <input id="password" type="password" placeholder="Password" Runat="Server" />
- <input id="confirm" type="password" placeholder="Confirm password" Runat="Server"/>
- <input id="email" type="text" placeholder="Email address" Runat="Server"/>
- <input id="phone" type="text" placeholder="Phone Number" Runat="Server"/>
- <input id="name" type="text" placeholder="Name" Runat="Server"/>
- <button onclick="Button1_Click">create</button>
- <p class="message">Already registered? <a href="login.aspx">Sign In
- <asp:SqlDataSource ID="SqlDataSource1" runat="server"
- ConnectionString="<%$ ConnectionStrings:regisString %>"
- SelectCommand="SELECT * FROM [regis]">
- </asp:SqlDataSource>
- </a></p>
- </form>
- </div>
- </div>
- </body>
- </asp:Content>
- 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 Register : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack)
- {
- SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["regisString"].ConnectionString);
- conn.Open();
- string checkuser = "select count(*) from Regis where username='" + username.Value + "'";
- SqlCommand cmd = new SqlCommand(checkuser, conn);
- int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
- if (temp == 1)
- {
- Response.Write("Student Already Exist");
- }
- conn.Close();
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- try
- {
- SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisString"].ConnectionString);
- conn.Open();
- string insertQuery = "insert into Regis(username,password,email,phone)values (@username,@password,@email,@phone,@name)";
- SqlCommand cmd = new SqlCommand(insertQuery, conn);
- cmd.Parameters.AddWithValue("@username",username.Value);
- cmd.Parameters.AddWithValue("@password",password.Value);
- cmd.Parameters.AddWithValue("@email",email.Value);
- cmd.Parameters.AddWithValue("@phone",phone.Value);
- cmd.Parameters.AddWithValue("@phone", name.Value);
- cmd.ExecuteNonQuery();
- Response.Write("Student registeration Successfully!!!thank you");
- conn.Close();
- }
- catch (Exception ex)
- {
- Response.Write("error" + ex.ToString());
- }
- }
- }
Add Comment
Please, Sign In to add comment