WB 例子 登录
HTML代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DengLu.aspx.cs" Inherits="DengLu" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <h1>登录</h1> <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label> <asp:TextBox ID="txtUid" runat="server"></asp:TextBox> <br /> <br /> <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label> <asp:TextBox ID="txtPwd" runat="server"></asp:TextBox> <br /> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="登录" /> <br /> </div> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </form> </body> </html>
后台C#代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class DengLu : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { testDataContext context = new testDataContext(); //取值 string uid = txtUid.Text; string pwd = txtPwd.Text; //查询 var query = context.Login.Where(p => p.UserName == uid && p.Password == pwd); if (query.Count() > 0) { Session["uid"] = uid; //跳转页面 Response.Redirect("Main.aspx"); } else { Literal1.Text = "<script type='text/javascript'>alert('用户名或密码错误!');</script>"; } } }
网页显示: