1 完成登入頁面(到記事本檔案進行密碼和使用者名稱的驗證)。
ASP中的代碼:
<form id="form1" runat="server">
<div>
<table align="center" border="1px" width="50%">
<tr><td class="style1" align="center"> 使用者名稱:</td> <td><input type="text" id="userName" runat="server" /></td></tr>
<tr><td class="style1" align="center">密碼:</td> <td><input type="password" id="passwordTxt" runat="server" /></td></tr>
<tr><td class="style1" align="center"><input style="width:79px;" type="button" id="btn_login" value="登入" Xonserverclick="Button1_Click" runat="server" /></td>
<td align="center"> <label id="htmlText" runat="server"></label></td></tr>
</table>
</div>
</form>
方法中的代碼:
protected void Button1_Click(object sender, EventArgs e)
{
string[] lines = File.ReadAllLines("password.txt");
string username=userName.Value;
string password=passwordTxt.Value;
for(int i=0;i<lines.Length;i++)
{
string[] line = lines[i].Split(' ');
if (line[0] == username && line[1] == password)
{
htmlText.InnerText = "登入成功!";
return;
}
else
{
htmlText.InnerText = "登入失敗!";
}
}
}
2 完成 使用者註冊頁面(將註冊資訊顯示在本頁面 div 中)。
ASP網頁中的代碼:
<form id="form1" runat="server">
<div>
<table align="center" border="1px" width="50%">
<tr><td class="style1" align="center"> 使用者名稱:</td> <td><input type="text" id="userName" runat="server" /></td></tr>
<tr><td class="style1" align="center">密碼:</td> <td><input type="password" id="passwordTxt" runat="server" Xonclick="return passwordTxt_onclick()" /></td></tr>
<tr><td class="style1" align="center">確認密碼:</td> <td><input type="password" id="passwordTxt1" runat="server" Xonclick="return passwordTxt_onclick()"/> <label id="label1" runat="server"></label> </td></tr>
<tr><td> 性別:</td> <td><input type="radio" id="radio1" runat="server" name="sex" />男 <input type="radio" id="radio2" name="sex" name="sex"/>女</td> </tr>
<tr><td>頭像:</td> <td><input type="file" id="file1" runat="server" /> </td></tr>
<tr><td class="style1" align="center"><input style="width:79px;" type="button" id="btn_login" value="登入" Xonserverclick=" Button1_Click" runat="server" /></td>
<td align="center"> <label id="htmlText" runat="server"></label></td></tr>
</table>
<div id="divResult" runat="server"></div>
</div>
</form>
方法中的代碼:
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("使用者名稱:");
sb.Append(userName.Value);
sb.Append("<br/>");
sb.Append("密碼:");
sb.Append(passwordTxt.Value);
sb.Append("<br/>");
if (passwordTxt.Value.Trim() == passwordTxt1.Value.Trim())
{
sb.Append("確認密碼:");
sb.Append(passwordTxt1.Value);
sb.Append("<br/>");
}
else
{
label1.InnerText = "兩次密碼不一致!!!";
passwordTxt.Value = "";
passwordTxt1.Value = "";
}
sb.Append("性別:");
if (radio1.Checked == true)
{
sb.Append("男");
}
else
{
sb.Append("女");
}
sb.Append("<br/>");
sb.Append("頭像");
string filename = file1.PostedFile.FileName;
filename = DateTime.Now.Ticks.ToString() + filename.Substring(filename.LastIndexOf("."));
this.file1.PostedFile.SaveAs(Server.MapPath("upLoad"+"\\"+filename));
sb.Append("<img src=\"upLoad/"+filename+"\"/>");
if (passwordTxt1.Value != "")
{
divResult.InnerHtml = sb.ToString();
}
}