<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Register TagPrefix="mynews" TagName="top" src="ascx/top.ascx"%>
<%@ Register TagPrefix="mynews" TagName="footer" src="ascx/footer.ascx"%>
<script language="VB" runat="server">
Dim sql As String
Dim myConn As OleDbConnection
Dim myCmd As OleDbCommand
'获取数据子程序
Function getdatareader(ByVal sql As String) As OleDbDataReader
myCmd = New OleDbCommand(sql, myConn)
myConn.Open()
getdatareader = myCmd.ExecuteReader()
End Function
'初始化退出登录
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./") & "DB_51aspx/news.mdb"
myConn = New OleDbConnection(strConn)
If Page.Request("action") = "logout" Then
Session("user") = ""
Response.Redirect("index.aspx")
End If
End Sub
'登录验证子程序
Sub addclick(ByVal sender As Object, ByVal e As EventArgs)
If username.Text = "" Then
message.Text = "请输入用户名!"
Else
If passward.Text = "" Then
message.Text = "请输入口令!"
Else
sql = "select username,passward from Admin where username='" & Trim(username.Text) & "'"
Dim userid, pass As String
Dim user As OleDbDataReader = getdatareader(sql)
While user.Read()
userid = user.Item(0)
pass = user.Item(1)
End While
myConn.Close()
If userid = "" Then
message.Text = "用户名不存在,请重新输入!"
username.Text = ""
passward.Text = ""
Else
If pass = passward.Text Then
Session("user") = "administrator"
message.Text = ""
Response.Redirect("newsmanager.aspx")
Else
message.Text = "口令错误!"
passward.Text = ""
End If
End If
End If
End If
End Sub
'清除变量信息子程序
Sub cancelclick(ByVal sender As Object, ByVal e As EventArgs)
message.Text = ""
username.Text = ""
passward.Text = ""
End Sub
</script>
<html>
<head>
<title>管理员登陆</title>
<link rel="stylesheet" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<mynews:top runat="server"/>
<form runat="server">
<table width="70%" cellspacing="0" cellpadding="1" align="center">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="40%" align="right" height="30">用户名:</td>
<td>
<asp:textbox ID="username" MaxLength="20" Columns="20" class="smallInput" runat="server"/>
</td>
</tr>
<tr>
<td align="right">密 码:</td>
<td>
<asp:textbox ID="passward" MaxLength="20" Columns="20" TextMode="Password" class="smallInput" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2" height="25" align="center">
<asp:label ID="message" ForeColor="red" runat="server"/>
</td>
</tr>
</table>
</td>
</tr>
<tr align="center">
<td height="40">
<asp:button ID="add" Text="登录" OnClick="addclick" class="buttonface" runat="server"/>
<asp:button ID="cancel" Text="取消" OnClick="cancelclick" class="buttonface" runat="server"/>
</td>
</tr>
</table>
</form>
<mynews:footer runat="server"/>
</body>
</html>
5 个解决方案
#1
把脚本里的放到后台就可
#2
http://bbs.csdn.net/topics/390683834?page=1#post-396498033
#3
你添加web窗体有没有把“将代码放在单独的文件中”前的复选框勾上
#4
#5
最简单就是新建页面,拷贝代码即可,分开放啊,通常高手都这样写,我也是,呵呵
#1
把脚本里的放到后台就可
#2
http://bbs.csdn.net/topics/390683834?page=1#post-396498033
#3
你添加web窗体有没有把“将代码放在单独的文件中”前的复选框勾上
#4
#5
最简单就是新建页面,拷贝代码即可,分开放啊,通常高手都这样写,我也是,呵呵