方法1:
在.aspx页面添加代码:
<script type="text/javascript">
function checkEmpty()
{
if(document.getElementById("txtUser").value=="")
{
alert("请输入用户名");
document.getElementById("txtUser").focus();
return false;
}
}
</script>
<style type="text/css">
<asp:Button ID="btn" runat="server" OnClientClick="return checkEmpty()" />
方法2:
if (txtUser.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名)</script>");
return;
}