实现数据的真实操作,
动态网页的代码:
<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" onclick="return passwordTxt_onclick()" /></td></tr>
<tr><td class="style1" align="center">确认密码:</td> <td><input type="password" id="passwordTxt1" runat="server" onclick="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="79px;" type="button" id="btn_login" value="登录" onserverclick=" 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();
}
}