html客户端服务器控件:
aspx:相当于设计文件,aspx.cs控制程序(1)给html代码加
runat=“server”,html服务端控件;(2)服务器端控件(托控件生成)以asp
开头的是高度封装的一类的形式存在;(1)和(2)的区别在于封装程度(2)是
高度封装的有各种属性和方法而(1)就没有那么多的属性方法,只能通过手动添
加;
cs文件:
using System;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)//单击提交按钮响应
{
string username = txtusername.Value;//通过控件的id的到对应的value值
string password=txtpassword.Value;
string[] lines= File.ReadAllLines("qq.txt");//读取文件中对应的用户名及密码
for (int i = 0; i < lines.Length;i++)//通过循环与文本框中的value值进行匹配判断是否正确
{
string[] line= lines[i].Split(' ');//通过分隔符将没行分成两个字符串即用户名和密码
if (line[0] == username && line[1] == password)
{ xianshi.InnerText="登陆成功"; return;}
}
xianshi.InnerText="登录失败";
}
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center" border="1px" width="50%">
<tr><td>用户名:</td><td><input type="text" id="txtusername" runat="server" /></td></tr>//搭结构runat="server"注明是代码在服务器端运行的
<tr><td>密码:</td><td><input type="text" id="txtpassword" runat="server" /></td></tr>
<tr><td><asp:Button ID="Button1" runat="server" Text="登陆" οnclick="Button1_Click" /></td><td><label id="xianshi" runat="server"></label></td></tr>
</table>
</div>
</form>
</body>
</html>