验证不适用于asp.net页面中的html控件。帮帮我。 [英] Validation is not working with html controls in asp.net page. Help Me Guys.

查看:48
本文介绍了验证不适用于asp.net页面中的html控件。帮帮我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

script type =text / javascript>

<! -

//表格验证码将来到这里。

function validate(){



if(document.myForm.name.value ==){

alert(请提供你的名字!);

document.myForm.Name.focus();

返回false;

}

if(document.myForm.Email.value ==)

{

alert(请提供您的电子邮件!);

document.myForm.EMail.focus();

返回false;

}





if(document.myForm.country.value ==)

{

alert(请提供你的国家!);

返回false;

}

return(true);

}

// - >

< / script>



script type="text/javascript">
<!--
// Form validation code will come here.
function validate() {

if (document.myForm.name.value == "") {
alert("Please provide your name!");
document.myForm.Name.focus();
return false;
}
if (document.myForm.Email.value == "")
{
alert("Please provide your Email!");
document.myForm.EMail.focus();
return false;
}


if (document.myForm.country.value == "")
{
alert("Please provide your country!");
return false;
}
return (true);
}
//-->
</script>

< form id =form1name =form1runat =serveronsubmit =return(validate());>



   
名称 < input name =nameid = nametype =textstyle =width:140px; >
电子邮件 < input name =Emailid =Emailtype =textstyle =width:140px; >
电话号码 <输入名称=Phonenoid =Phonenotype =textstyle =width:140px; >
国家 < input name =countryid =countrytype =textstyle =width:140px; >
评论 < textarea name =commentsstyle =width:140px; rows =2class =txtbox1id =comments>< / textarea>
  < asp:Button ID =Buttonsubmitrunat =serverText =提交查询

onclick = Buttonsubmit_Click/>


< / form>

<form id="form1" name="form1" runat="server" onsubmit="return(validate());">

   
Name <input name="name" id="name" type="text" style="width:140px;" >
Email <input name="Email" id="Email" type="text" style="width:140px;" >
Phone Number <input name="Phoneno" id="Phoneno" type="text" style="width:140px;" >
Country <input name="country" id="country" type="text" style="width:140px;" >
Comments <textarea name="comments" style="width:140px;" rows="2" class="txtbox1" id="comments"></textarea>
  <asp:Button ID="Buttonsubmit" runat="server" Text="Submit Query"
onclick="Buttonsubmit_Click" />

</form>

推荐答案

检查这个





Check this


<asp:Button ID="Buttonsubmit" runat="server" Text="Submit Query"
onclick="Buttonsubmit_Click" onclientclick="validate()" /> 


<asp:Button ID="Buttonsubmit" runat="server" Text="Submit Query"
onclick="Buttonsubmit_Click" onclientclick="return validate()" />







如果语法错误,还会检查浏览器是否有javascript错误然后不会调用此验证函数




also check your browser for javascript error if there is syntax error then this validation function will not be called


这篇关于验证不适用于asp.net页面中的html控件。帮帮我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆