日期:2014-05-17  浏览次数:20373 次

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">
&nbsp;性别: 
  <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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <asp:ListBox ID="ListBox1" runat=&quo