js前台验证asp:TextBox
<script language="javascript">function cheack()
{
if(document.getElementById("TextBox1").value=="")
{
alert("联系电话不能为空!");
document.getElementById("TextBox1").focus();
return false;
}
if(document.getElementById("TextBox2").value=="")
{
alert("22222222222");
document.getElementById(TextBox2).focus();
return false;
}
if(document.getElementById("TextBox3").value=="")
{
alert("ccccccccccccc");
document.getElementById(TextBox3).focus();
return false;
}
return true;
}
function cc()
{
document.getElementById("TextBox1").focus();
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onload="cc();">
<form id="Form1" method="post" runat="server">
联系电话<asp:TextBox id="TextBox1"
runat="server"></asp:TextBox>
联系电话2<asp:TextBox id="TextBox2"
runat="server"></asp:TextBox>
联系电话88<asp:TextBox id="TextBox3"
runat="server"></asp:TextBox>
<asp:Button id="Button1"runat="server"
Text="Button" onclick="return cheack();"></asp:Button>
</form>
我这样写他提示错误:
Compiler Error Message: CS1041: Identifier expected, 'return' is a keyword
Source Error:
Line 42: <asp:Button id="Button1" 304px" runat="server" -------红色
Line 43: Text="Button" onclick="return cheack();"></asp:Button>
--------------------编程问答-------------------- <form id="Form1" method="post" runat="server">
联系电话<asp:TextBox id="TextBox1"runat="server"></asp:TextBox> 联系电话2<asp:TextBox id="TextBox2"runat="server"></asp:TextBox>
联系电话88<asp:TextBox id="TextBox3" runat="server"></asp:TextBox>
<asp:Button id="Button1"runat="server"Text="Button"</form>
后台 .cs
private void Button1_Click(object sender, System.EventArgs e)
{
this.Button1.Attributes.Add("onclick","return cheack();");
Response.Write("dddddddddddddddddddddddddddddddddd");
}
这样的话 他执行了 Response.Write("dddddddddddddddddddddddddddddddddd");才返回(onclick)
--------------------编程问答-------------------- OnClientClick --------------------编程问答--------------------
<asp:Button id="Button1"runat="server"
Text="Button" OnClientClick="return cheack()" > </asp:Button >
<script language="javascript" >
function cheack()
{
if(document.getElementById("TextBox1").value=="")
{
alert("联系电话不能为空!");
document.getElementById("TextBox1").focus();
return false;
}
if(document.getElementById("TextBox2").value=="")
{
alert("22222222222");
document.getElementById(TextBox2).focus();
return false;
}
if(document.getElementById("TextBox3").value=="")
{
alert("ccccccccccccc");
document.getElementById(TextBox3).focus();
return false;
}
return true;
}
</script > --------------------编程问答-------------------- 我用的是2003
是不是没有这个事件
function cheack()
{alert("asdfasdfsd");
}
<asp:Button id="Button1" runat="server" Text="Button" OnClientClick="return cheack()"></asp:Button>
没反映 --------------------编程问答-------------------- 用这样就可以了
<input id="Button2" type="button" value="button" onclick="return Check()" runat="server"/> --------------------编程问答--------------------
45 --------------------编程问答-------------------- this.Button1.Attributes.Add( "onclick ", "return cheack(); ");
这个加到page——load()里面
补充:.NET技术 , ASP.NET