Hi,
How to create simple registration page with username ,pwd, screen name, security question with validation coding
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Apr 10, 2012, 10:40 AM
Try this...
Here all types of validation are provided.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Create_a_user_account_Csharp._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Create_a_user_account_Csharp
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from secret";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
ddlsecurityquestion.Items.Add(reader["secretqno"].ToString());
}
reader.Close();
con.Close();
}
protected void b1_Click(object sender, EventArgs e)
{
Session["name"] = txtname.Text;
SqlConnection con = new SqlConnection(connStr);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into useraccount(userid,name,password,confirmpassword,email,securityquestion,securityanswer) values(@userid,@name,@password,@confirmpassword,@email,@securityquestion,@securityanswer)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@userid", txtid.Text);
com.Parameters.AddWithValue("@name", txtname.Text);
com.Parameters.AddWithValue("@password", txtpassword.Text);
com.Parameters.AddWithValue("@confirmpassword", txtconfirmpassword.Text);
com.Parameters.AddWithValue("@email", txtemail.Text);
com.Parameters.AddWithValue("@securityquestion", ddlsecurityquestion.SelectedValue);
com.Parameters.AddWithValue("@securityanswer", txtsecurityanswer.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
Response.Redirect("success.aspx");
}
}
}
Thanks
If this post helps you mark it as answer
SenthilkumarPosted Apr 10, 2012, 5:41 AM
Design page:
Code file: