Asp.net实际问题 [英] Asp.net Practical problems
本文介绍了Asp.net实际问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了简单的注册页面和登录页面,当我登录时我放了一个按钮然后我点击那个按钮,我想用我的详细信息显示我的注册表单,我想要更新并保存结果,如何做到这一点..任何人给出简单实用的解释和代码......我认为这可能很难....
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....
推荐答案
使用这个..
Use this..
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");
}
}
这篇关于Asp.net实际问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文