Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i created simple registration page and login page ,when i login i put a button then i click on that button ,i want to show my registration form with my details and there i want update and save the result ,how to do this ..anyone give simple practical explanation and code..i think it may be difficult....
Posted
Comments
Thanks7872 9-Dec-14 5:39am    
No. Its not difficult. Learn asp.net using tutorials available online and you will be able to do it.
Member 10458660 9-Dec-14 7:28am    
Rohan leuva ..if you have any good material or concepts please share .......thank you

1 solution

Use this..
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;

public partial class AdminLogin : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        clearCookies();
        txtUname.Focus();
    }

  
    private void clearCookies()
    {
        if (Request.Cookies.Count > 0)
        {
            Request.Cookies.Clear();
            Response.Cookies["UserData"].Expires = DateTime.Now.AddDays(-1);
        }
    }

    protected void BtnLogin_Click(object sender, EventArgs e)
    {
       try
        {
            bool lStatus = verifyLogin();
            if (lStatus)
            {
                DataTable dts = (DataTable)ViewState["UserData"];
                //Creating User Cookies
                HttpCookie userData = new HttpCookie("UserData");
                DateTime dt = DateTime.Now;
                userData["Username"] = txtUname.Text.ToLower();
                userData["Token"] = dts.Rows[0]["Token"].ToString();
                userData.Expires = dt.AddMinutes(20);
                Response.Cookies.Add(userData);
                //End Of Creating User Cookies

                if (dts.Rows[0]["Token"].ToString() == "111")
                {
                    Response.Redirect("Home.aspx");
                }
            }
            else 
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Invalid Credentials", "alert('User Does Not Exists..!')", true);
                lblerr.Text = "Incorrect user(or) Password";
                lblerr.ForeColor= Color.Red;
            }
        }
        catch (Exception ee)
        {
           
        }
    }
    public bool verifyLogin()
    {
        bool sts = false;
        string Query = "select * from tablename_login where Username='" + txtUname.Text.ToLower() + "' and password='" + txtPwd.Text + "' ";
        DataTable dt = DAL.getData(Query);
        if (dt.Rows.Count > 0)
        {
            sts = true;
            ViewState["UserData"] = dt;
        }
        return sts;
    }
   
   protected void btncancel_Click(object sender, EventArgs e)
   {
       Response.Redirect("AdminLogin.aspx");
   }
}
 
Share this answer
 
v2
Comments
Thanks7872 9-Dec-14 6:40am    
Before posting this answer, did you think that how this can be helpful to some one who has never coded anything?

How OP will come to know what is the purpose of if (dt.Rows.Count > 0)?
CP_vicky 9-Dec-14 6:45am    
Instead of keep calm at least i shared what i know and i expect from him is if he understand single line also that will be good for me.. don't discourage some one sharing the knowledge to some one which he knows a bit also
Member 10458660 9-Dec-14 7:26am    
Thankyou very much brother giving reply and a good information.. in future i hope u will answer my questions cp_vicky
CP_vicky 9-Dec-14 7:37am    
Welcome bro.. See how crazy.. down voted some one's answer(if it really poor answer you can, but its a related answer know). you know the dot net by birth or what. any one can learn any thing. Sorry bro..Rohan Leuva

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