protected void Button1_Click(object sender, EventArgs e)
{
if(TextBox1.Text=="")
{
Response.Write("<script>alert('不能为空');</script>");
return;
}
}我是这样写的,虽然界面返回但是仍然会先提交界面我不想用ajax,也不想在客户端用脚本验证返回,怎么解决?这应该是个很小白的问题吧望高人指点
{
if(TextBox1.Text=="")
{
Response.Write("<script>alert('不能为空');</script>");
return;
}
}我是这样写的,虽然界面返回但是仍然会先提交界面我不想用ajax,也不想在客户端用脚本验证返回,怎么解决?这应该是个很小白的问题吧望高人指点
沙发!
要么在服务器验证,要么在客户端验证,要在服务器验证,按一定要提交了。
{
var c = document.getElementById("TextBox1");
if (c.value == null || c.value == "")
{
alert("textBox1 为空。");
c.focus();
return false;
}
return true;
}Button1.Attributes.Add("onclick", "return checkText();");
<ASP:TextBox id="txtName" RunAt="Server"/>
<ASP:RequiredFieldValidator id="Validator1" Runat="Server"
C
ErrorMessage="姓名必须输入"
Display="Static">
*姓名必须输入
</ASP:RequiredFieldValidator>
<script>
function CheckNull()
{
var obj=document.getElementById("TextBox1");
if(obj.value='')
{
alert("textBox1 为空");
}
}
</script>
protected void Button1_Click(object sender, EventArgs e)
{
if(TextBox1.Text=="")
{
Response.Write(" <script>alert('不能为空');window.location='index.aspx'; </script>");
return;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if(TextBox1.Text=="")
{
Response.Write(" <script>alert('不能为空');window.location.href='index.aspx'; </script>");
}
}
“我不想用ajax,也不想在客户端用脚本验证返回”,这两个都可以认为是使用 js 脚本的客户端验证。既不想服务器端验证,也不想客户端验证,那你想谁来验证?
function checkText()
{
var c = document.getElementById("TextBox1");
alert("textBox1 为空。");
c.focus();
return false;
}
C#
private void Page_Load(object sender, System.EventArgs e)
{
if(TextBox1.Text=="")
{
codeButton1.Attributes.Add("onclick", "return checkText();");
}
}
这个可不可以,我是来学习的~