我想实现的功能是,用户在登陆框那里输入用户名和密码,如果登陆成功即用户名和密码正确
就在原来登陆的那里 用户名:显示刚刚登陆的用户名 密码:这项就不显示啦
代码如下:
帮我看看,我该怎么去写他,是要在HTML代码中嵌入C#还是怎么样???
Default2.aspx页面:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style></head>
<body>
<form id="form1" runat="server">
<div>
<div style="text-align: center">
<div style="text-align: center">
<div style="text-align: center">
<table width="431" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="50" style="height: 28px">用户名:</td>
<td width="50" style="height: 28px">
<asp:TextBox ID="username" runat="server">username</asp:TextBox></td>
<td width="164" style="height: 28px">密码:</td>
<td width="167" style="height: 28px">
<asp:TextBox ID="pwd" runat="server">pwd</asp:TextBox></td>
</tr>
<tr>
<td colspan="4"><div align="center">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" /> </div></td>
</tr>
</table>
</div>
</div>
</div> </div>
</form>
</body>
</html>
Default2.aspx.cs页面:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.username.Text = "";
this.pwd.Text = ""; } }
protected void Button1_Click(object sender, EventArgs e)
{
string username = this.username.Text;
string pwd = this.pwd.Text;
string connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database\\database.mdb");
OleDbConnection conn = new OleDbConnection(connectionstring);
conn.Open(); DataSet ds = new DataSet();
OleDbCommand cm = new OleDbCommand();
cm.CommandText = "select * from [admin] where username='" + username + "' and password='" + pwd + "'";
cm.Connection = conn;
OleDbDataAdapter Adapter = new OleDbDataAdapter();
Adapter.SelectCommand = cm;
Adapter.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Session["login"] =true;
Session["loginusername"] = username;
Response.Redirect("Default2.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码错误')</script>");
Response.Write("<script>location.href='Default2.aspx'</script");
}
}
}也就是在返回的时候
在原来的页面是显示 用户名:显示刚刚登陆的用户名 密码:这项就不显示啦
就在原来登陆的那里 用户名:显示刚刚登陆的用户名 密码:这项就不显示啦
代码如下:
帮我看看,我该怎么去写他,是要在HTML代码中嵌入C#还是怎么样???
Default2.aspx页面:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style></head>
<body>
<form id="form1" runat="server">
<div>
<div style="text-align: center">
<div style="text-align: center">
<div style="text-align: center">
<table width="431" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="50" style="height: 28px">用户名:</td>
<td width="50" style="height: 28px">
<asp:TextBox ID="username" runat="server">username</asp:TextBox></td>
<td width="164" style="height: 28px">密码:</td>
<td width="167" style="height: 28px">
<asp:TextBox ID="pwd" runat="server">pwd</asp:TextBox></td>
</tr>
<tr>
<td colspan="4"><div align="center">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" /> </div></td>
</tr>
</table>
</div>
</div>
</div> </div>
</form>
</body>
</html>
Default2.aspx.cs页面:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.username.Text = "";
this.pwd.Text = ""; } }
protected void Button1_Click(object sender, EventArgs e)
{
string username = this.username.Text;
string pwd = this.pwd.Text;
string connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database\\database.mdb");
OleDbConnection conn = new OleDbConnection(connectionstring);
conn.Open(); DataSet ds = new DataSet();
OleDbCommand cm = new OleDbCommand();
cm.CommandText = "select * from [admin] where username='" + username + "' and password='" + pwd + "'";
cm.Connection = conn;
OleDbDataAdapter Adapter = new OleDbDataAdapter();
Adapter.SelectCommand = cm;
Adapter.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Session["login"] =true;
Session["loginusername"] = username;
Response.Redirect("Default2.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码错误')</script>");
Response.Write("<script>location.href='Default2.aspx'</script");
}
}
}也就是在返回的时候
在原来的页面是显示 用户名:显示刚刚登陆的用户名 密码:这项就不显示啦
解决方案 »
- 第二个table中的img,我在上面加了一个a标签,他下面就会多出几像素,求解
- ASP.net 读取MySql 数据出现中文乱码!
- 一个郁闷的问题!请高手快来解答!
- 在aspx下写JS load xml 的灵异事件
- web 连接的问题
- 请高手帮我做一个C++.net小程序,可以吗?
- 请教关于Asp.net里的Web.config的Access数据库连接字符串的问题?
- 关于sql server
- Looking for a ASP.NET coder
- 怎么在代码中方便地加入一个事件函数呀?
- 请问大家一个水晶报表安装部署的问题,谢谢了~~
- |M| 如何在网页中获取当前DIV后面的DIV的innerHTML 如何改变页面中<A>href="a.aspx"为"b.aspx" 谢谢
<td width="50" style="height: 28px">用户名:</td>
<td width="50" style="height: 28px">
<asp:TextBox ID="username" runat="server">username</asp:TextBox></td>
<td width="164" style="height: 28px">密码:</td>
<td width="167" style="height: 28px">
<asp:TextBox ID="pwd" runat="server">pwd</asp:TextBox></td>
</tr>
也就是当也面返回时这里该怎样处理??????
{
bool login = (bool)Session["login"];
if (login)
{
this.username.Text = Session["loginusername"].ToString();
}
else
{
this.username.Text = "";
this.pwd.Text = "";
}
}
{
bool login = false;
if (Session["login"] != null)
{
login = (bool)Session["login"];
}
if (login)
{
this.username.Text = Session["loginusername"].ToString();
}
else
{
this.username.Text = "";
this.pwd.Text = "";
}
}