求助 当前的上下文中不存在名称
本人按照视频学习.net,遇到一个问题,显示 当前上下文中不存在名称“txtUserName” 查网页说是指向两个cs文件,怎么找也没有找出来,请高手指点。 如下代码 不胜感激<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="注册.aspx.cs" Inherits="注册登录1.注册" %>
<!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 id="Head1" runat="server">
<title>注册用户</title>
<style type="text/css">
.error{background:Red;}
.style1
{
height: 27px;
}
</style>
<script src="js/jquery-1.8.3.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#<%=txtPassword.ClientID%>").blur(function () {
var str = $(this).val();
if (str.length <= 6) {
$("#passwordLevel").text("弱");
}
else {
var regex = /\W/; //判断是否含有非字母数字
if (regex.test(str)) {
$("#passwordLevel").text("强");
}
else {
$("#passwordLevel").text("中");
}
}
});
$("#<%=form1.ClientID %>").submit(function (e) {
var pwd1 = $("#<%=txtPassword.ClientID %>").val();
var pwd2 = $("#<%=txtPassword2.ClientID %>").val();
if (pwd1 != pwd2) {
alert("两次输入的密码不一致");
return false;
e.preventDefault();
}
var email = $("#<%=txtEmail.ClientID %>").val();
var regex = /.+@.+/;
if (!regex.test(email)) {
alert("Email地址格式不正确");
return false;
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr><td>
<asp:Label ID="Label1" runat="server" Text="用户名" AssociatedControlID="txtUserName"></asp:Label></td><td>
<asp:TextBox ID="txtUserName" runat="server" AutoPostBack="true"
ontextchanged="txtUserName_TextChanged"></asp:TextBox>
<asp:Label ID="labelUserName" runat="server" Text="Label" CssClass="error" Visible="False"></asp:Label>
</td>
</tr>
<tr><td>
<asp:Label ID="Label2" runat="server" Text="密码"></asp:Label></td><td>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>密码强度:<span id="passwordLevel"></span></td></tr>
<tr><td>
<asp:Label ID="Label3" runat="server" Text="再次输入密码"></asp:Label></td><td>
<asp:TextBox ID="txtPassword2" runat="server"></asp:TextBox></td></tr>
<tr><td>
<asp:Label ID="Label4" runat="server" Text="邮箱"></asp:Label></td><td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td></tr>
<tr><td class="style1">
<asp:Button ID="btnRegister" runat="server" Text="注册"
onclick="btnRegister_Click" />
<asp:Label ID="Label" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label5" runat="server" Text="Label" Visible="False" ></asp:Label>
</td></tr>
</table>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using 注册登录1.DAL.DataSetUsersTableAdapters;
namespace 注册登录1
{
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void txtUserName_TextChanged(object sender, EventArgs e)
{
T_UsersTableAdapter adapter = new T_UsersTableAdapter();
if (adapter.GetDataByUserName(txtUserName.Text).Count >= 1)
{
labelUserNameErrorMsg.Visible = true;
labelUserNameErrorMsg.Text = "此用户名已存在";
}
else
{ labelUserNameErrorMsg.Visible = false; }
}
protected void btnRegister_Click(object sender, EventArgs e)
{
if (txtPassword.Text != txtPassword2.Text)
{
// Label1ErrorMsg.Text = "两次输入的密码不一致";
// LabelErrorMsg.Visible = true;
Label5.Text = "两次输入的密码不一致";
}
}
}
}
补充:.NET技术 , ASP.NET