我写了一段程序是判断用户输入的用户名是否已经存在!
我写了一个TextBox和一个Button!
具体代码如下!
<body>
<form name="form1" method="post" action="" runat="server" ID="Form1">
<asp:TextBox ID="txtName" Runat="server"></asp:TextBox>
         <asp:Button ID="btSel" OnClick="btSelClick" Runat="server" Text="检查用户名"></asp:Button>
</form>
</body>
按钮事件!
private void btSelClick(object sender, System.EventArgs e)
{

  SqlCommand com=new SqlCommand("select name from studnet where id='"+txtName.Text+"'",conn);

conn.Open();
SqlDataReader dr=preCom.ExecuteReader();

if(dr.HasRows && dr.Read())
{
string strScript = "<script";
strScript += ">";
strScript += "alert("您输入的用户名已经存在!");<";
strScript += "/script>";
Page.RegisterStartupScript("", strScript);
}
}
我同样写了两种RegisterStartupScript都报错!
Page.RegisterStartupScript("","<script>alert("您输入的卡号不存在");</script>");这是为什么啊!!
请给我解释解释!帮我改改!

解决方案 »

  1.   

    Page.RegisterStartupScript("","<script>alert('您输入的卡号不存在');</script>");单引号。下次发帖子,少用感叹号。
      

  2.   

    strScript += "alert("您输入的用户名已经存在!");<";
    这句有问题,改成:
    strScript += "alert('您输入的用户名已经存在!');<";

    strScript += "alert(\"您输入的用户名已经存在!\");<";
      

  3.   

    Page.RegisterStartupScript("", strScript);
    注册一个名称试试,不要用"",另外上面说的也是问题