我在.cs中Page_Load()中添加了如下代码 Button.Attributes.Add("onclick","return check();"); 下面是check方法的具体内容
function check()
{
if(document.Form1.TextBox1.value=="")
{
alert("false");
return false;
}
else
{
alert("true");
return true;
}
}
下面是Button服务器端的Click方法的具体实现
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("asdfasdf");
}但不关check方法返回true还是false
服务端的代码都不执行请问一下要怎么改才会在check方法返回true的时候执行服务器端的代码
function check()
{
if(document.Form1.TextBox1.value=="")
{
alert("false");
return false;
}
else
{
alert("true");
return true;
}
}
下面是Button服务器端的Click方法的具体实现
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("asdfasdf");
}但不关check方法返回true还是false
服务端的代码都不执行请问一下要怎么改才会在check方法返回true的时候执行服务器端的代码
和一个buttonthis.Button1.Click += new System.EventHandler(this.Button1_Click);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm4</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script type="text/javascript">
function check()
{
if(document.Form1.TextBox1.value=="")
{
alert("false");
return false;
}
else
{
alert("true");
return true;
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="WebForm4.aspx" id="Form1" onsubmit="return false">
<input type="hidden" name="__VIEWSTATE" value="dDwxMDA0NDg0NTY3O3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDM+Oz47bDx0PHA8O3A8bDxvbmNsaWNrOz47bDxyZXR1cm4gY2hlY2soKVw7Oz4+Pjs7Pjs+Pjs+Pjs+SalyRxgdWtSqpqQw0P9dTVT5vRg=" /> <input name="TextBox1" type="text" id="TextBox1" style="Z-INDEX: 101; LEFT: 368px; POSITION: absolute; TOP: 72px" />
<input type="submit" name="Button1" value="Button" id="Button1" onclick="return check();" style="Z-INDEX: 102; LEFT: 368px; POSITION: absolute; TOP: 120px" /></form>
</body>
</HTML>
<form name="Form1" method="post" action="WebForm4.aspx" id="Form1" onsubmit="return false">
我加了onsubmit="return false"这个
结帖了