ASP.NET中TextBox中的内容在选定ListBox里面的选项后消失,ListBox中的AutoPostBack属性为True
完整的程序代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="sy1.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>
<style type="text/css">
.style1
{
font-size: xx-large;
text-align: left;
}
.style3
{
text-align: left;
height: 19px;
}
.style4
{
text-align: left;
height: 18px;
}
.style5
{
text-align: left;
}
</style>
<script language="javascript" type="text/javascript">
function fCheck() {
alert("您输入的密码:" + form1.TextBox3.value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<p class="style1">
用户注册</p>
<p class="style5">
用户名:<asp:TextBox ID="TextBox1" runat="server"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="不能为空"></asp:RequiredFieldValidator>
</p>
<p class="style5">
真实姓名:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
<p class="style5">
密码:<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="密码至少6位"
ValidationExpression="\S{6,16}"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox3" ErrorMessage="密码至少6位"></asp:RequiredFieldValidator>
</p>
<p class="style3">
性别:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem>男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList>
</p>
<p class="style4">
职业:</p>
<asp:ListBox ID="ListBox1" runat="server" Height="90px" AutoPostBack="True"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>学生</asp:ListItem>
<asp:ListItem>公务员</asp:ListItem>
<asp:ListItem>工人</asp:ListItem>
<asp:ListItem>农民</asp:ListItem>
<asp:ListItem>教师</asp:ListItem>
</asp:ListBox>
<p>
<asp:Label ID="Label1" runat="server">固定电话:</asp:Label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox4" ErrorMessage="格式为XXX-XXXXXXXX"
ValidationExpression="(\(\d{3}\)|\d{3}-)?\d{8}"></asp:RegularExpressionValidator>
</p>
<p>
移动电话:<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</p>
<p>
出生日期:<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
年<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
月<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
日</p>
<p>
E-mail:<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ControlToValidate="TextBox6" ErrorMessage="输入格式不正确"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</p>
<p>
个人主页:<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="确定" onclick="Button1_Click"
onclientclick="return confirm('确实要提交吗?')" />
<asp:Button ID="Button2" runat="server" Text="清空" onclick="Button2_Click"
style="height: 26px" />
<asp:Button ID="Button3" runat="server" Text="显示密码" onclick="Button3_Click"
onclientclick="fCheck()" />
</p>
<p>
<asp:TextBox ID="TextBox8" runat="server" Height="163px" TextMode="MultiLine"
Width="426px"></asp:TextBox>
</p>
</form>
<p>
</p>
</body>
</html>
问题是:当我选择学生和其它的ListBox中的选项的时候密码框中的内容就没了
不知道该怎么解决
[解决办法]
+一个ajax,局部刷新
[解决办法]
如果
TextBox不是TextMode=Password是不会消失内容的
TextMode=Password的textbox必须在后台得到内容赋值
TextBox1.Attributes.Add("value",TextBox1.Text)