2015-7-17

正则表达式

利用ajax实现页面免刷新

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="True">//这里面放要免刷新的东西
<ContentTemplate>
<asp:TextBox ID="txtName" runat="server" OnTextChanged="txtName_TextChanged" AutoPostBack="True"></asp:TextBox>
<asp:Label ID="labUser" runat="server"></asp:Label>
<asp:Label ID="labIsName" runat="server"></asp:Label>
<br />
<asp:TextBox ID="txtPass" runat="server" AutoPostBack="True" OnTextChanged="txtPass_TextChanged" TextMode="Password"></asp:TextBox>
<asp:Label ID="labEbb" runat="server"></asp:Label>
<asp:Label ID="labStrong" runat="server"></asp:Label>

</ContentTemplate>
</asp:UpdatePanel>

http://blog.163.com/ghost____/blog/static/32319537201242652825647/     推荐这篇博客

//设置正则表达式
Regex re = new Regex("^\w+$");
//使用Regex对象中的isMatch()方法判断用户名是否满足正则表达式
if (re.IsMatch(txtName.Text))
{
blNameFormar = true;
labUser.ForeColor = System.Drawing.Color.Black;
}

labUser.ForeColor = System.Drawing.Color.Red;//设置背景色

另一种使用数据库的方式

if (Request.Cookies["CheckCode"].Value == code)
{
//创建数据库连接
SqlConnection conn = new SqlConnection(str);
//打开数据库连接
conn.Open();
//使用MD5加密,将用户输入的密码加密
string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtUserpass.Text, "MD5");
//创建sql语句,用来查询用户输入的用户名和密码是否正确
string sqlSel = "select count(*) from tb_userInfo where userName=@name and userPass=@pass";
//创建sqlcommand对象
SqlCommand comm = new SqlCommand(sqlSel, conn);
//使用Parameters的Add()方法添加参数类型
comm.Parameters.Add(new SqlParameter("name", SqlDbType.VarChar, 20));
//设置Paramters的参数值
comm.Parameters["name"].Value = txtUserName.Text;
comm.Parameters.Add(new SqlParameter("pass", SqlDbType.VarChar, 20));
comm.Parameters["pass"].Value = pass;
//判断ExecuteScalar()方法返回的参数是否大于0,若大于表示登录成功,并给出提示
if (Convert.ToInt32(comm.ExecuteScalar()) > 0)
{
RegisterStartupScript("", "<script>alert('登录成功!')</script>");
txtCode.Text = txtUserName.Text = "";
}

onfocus事件 鼠标点击文本框时触发

<input id="Text1" type="text" onfocus="tName();"/>

<script>
function tName() {
document.getElementById("Label1").innerHTML = "hhh";
}
</script>

原文地址:https://www.cnblogs.com/wangkaipeng/p/4655411.html