?? default.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
//該源碼下載自www.51aspx.com(51aspx.com)
namespace school
{
/// <summary>
/// WebForm1 的摘要說明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
//聲明Default文件中使用的表格表單、變量。
protected System.Web.UI.WebControls.Label lblMsg;
protected System.Web.UI.WebControls.TextBox Pwd;
protected System.Web.UI.WebControls.Button btnreg;
protected System.Web.UI.WebControls.TextBox login;
protected System.Web.UI.WebControls.Button btnOK;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
if(!Page.IsPostBack)
{
lblMsg.Text="";
login.Text="";
Pwd.Text="";
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
this.btnreg.Click += new System.EventHandler(this.btnreg_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnOK_Click(object sender, System.EventArgs e)
{
//建立與數(shù)據(jù)源的連接
string sqlconn = ConfigurationSettings.AppSettings["SQLConnectionString"];
SqlConnection myConnection = new SqlConnection(sqlconn);
string id=login.Text.ToString();
string pass=Pwd.Text.ToString();
string sql="select * from userreg where login='"+id+"'and password='"+pass+"'";
SqlCommand cmd = new SqlCommand(sql, myConnection);
//打開連接
myConnection.Open();
//讀取數(shù)據(jù)庫數(shù)據(jù)
SqlDataReader rs=cmd.ExecuteReader();
//驗證用戶的身份
if(rs.Read())
{
//將用戶的id值賦值給Session
Session["uid"]=rs["id"].ToString();
Page.Response.Redirect("school.aspx");
}
else
{
lblMsg.Text="用戶名或口令錯誤!請重新輸入!";
Pwd.Text="";
}
//關閉數(shù)據(jù)庫連接
myConnection.Close();
}
private void btnreg_Click(object sender, System.EventArgs e)
{
lblMsg.Text="";
login.Text="";
Pwd.Text="";
Page.Response.Redirect("regedit.aspx");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -