Monday 26 October 2015

Data Transfer in asp.net



WebForm1 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPproject
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            Server.Transfer("WebForm2.aspx");
        }

        public string Name
        {
            get {
                return txtName.Text;
            }
     
        }
        public string Email
        {
            get {
                return txtEmail.Text;
            }
        }
    }
}






                                                                        WebForm2 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPproject
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Page lastPage=(Page)Context.Handler;
            //lblName.Text = ((TextBox)lastPage.FindControl("txtName")).Text;
            //lblEmail.Text = ((TextBox)lastPage.FindControl("txtEmail")).Text;


        }
    }
}

Wednesday 21 October 2015

Page Navigation Server.Transver








using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Asp_Project
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            Server.Transfer("~/WebForm2.aspx", false);
        }

        protected void btnredirec_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/WebForm2.aspx");
        }

     
    }
}














using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

namespace Asp_Project
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //NameValueCollection previousformCollection = Request.Form;
            //lblName.Text = previousformCollection["txtName"];
            //lblEmail.Text = previousformCollection["txtEmail"];

            Page perviouspage = Page.PreviousPage;

            if (perviouspage != null)
            {
                lblName.Text = ((TextBox)perviouspage.FindControl("txtName")).Text;
                lblEmail.Text = ((TextBox)perviouspage.FindControl("txtName")).Text;
            }

         
         
        }
    }
}

Wednesday 7 October 2015

Login/Registration Form in C# window Application Form


Login.cs







using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace user_login
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=ASP4-PC\SQLEXPRESS;Initial Catalog=comsoul1;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * from comsoul_registration where Fname = '"+txtUser.Text+"' and Password = '"+txtPass.Text+"'", con );
            SqlDataReader reader = cmd.ExecuteReader();
         
            int count = 0;
            while(reader.Read())
            {
                count += 1;
            }
            if (count == 1)
            {
                MessageBox.Show("OK");
                Registraion f2 = new Registraion();
                f2.Show();
            }
            else if(count > 0){
                MessageBox.Show("Doublicate user and Password");
         
            }
            else{
                MessageBox.Show("UserName and Password not correct");
            }

            txtUser.Clear();
            txtPass.Clear();
     }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
     
    }
}



Registraion.cs




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;


namespace user_login
{
    public partial class Registraion : Form
    {
        //C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE

        string path = @"Data Source=ASP4-PC\SQLEXPRESS;Initial Catalog=comsoul1;Integrated Security=True";

        public Registraion()
        {
            InitializeComponent();
        }

        private void btnregister_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(path);
            if (con.State != ConnectionState.Open)
            {
                con.Open();
                string addquery = string.Format("insert into comsoul_registration (Fname,Lname, Phone, Street, Zip_code, Email, Password,Re_enter, Creadit_card,Creadit_card_type,Date_Time) values('" + 
                                                                                        txtFname.Text + "','" + txtLname.Text + "','" + txtPhone.Text + "', '" + txtStreet.Text + "', '" + txtZip.Text + "','" + txtEmail.Text + "','" + txtPassword.Text + "', '" + txtRepassword.Text + "','" + txtCcard.Text + "','" + txtCcard2.Text + "','" + txtdate.Value.Date + "')");

                SqlCommand cmd = new SqlCommand(addquery,con);

                var roweffected = cmd.ExecuteNonQuery();


                MessageBox.Show("Inserted Data !");

                txtFname.Text = null;
                txtLname.Text = null;
                txtPhone.Text = null;
                txtStreet.Text = null;
                txtZip.Text = null;
                txtEmail.Text = null;
                txtPassword.Text = null;
                txtRepassword.Text = null;
                txtCcard.Text = null;
                txtCcard2.Text = null;
              
            }
            else
            {
                con.Close();

            }

        }

        private void btncancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}





database





create  database comsoul1
  
  create table comsoul_registration
  (
id int primary key identity,
[Fname] varchar (50),
[Lname] varchar (50),
[Phone] int,
[Street] varchar (50),
[City] varchar (50),
[Zip_code] int,
[Email] varchar (50),
[Password] varchar (50),
[Re-enter] varchar (50),
[Creadit_card] int,
[Creadit_card_type] varchar (50),
  )
  
  alter table comsoul_registration
  add [Date_Time] datetime
  
  select * from comsoul_registration