javascript验证警告msgs未显示在母版页中 [英] javascript validation alert msgs not showing in masterpage

查看:78
本文介绍了javascript验证警告msgs未显示在母版页中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了2webforms登录和注册。后来我创建了母版页。我已将这些包含在masterpage中的页面中。但问题是我在javascript中的验证不能在masterpage上工作..它不显示警告消息,如填充名字等。当没有母版页运行此表单时,所有验证都正常工作这个问题的解决方案是什么。

这里有一些代码:

< script type =text / javascript>

function Validateform(){

var Firstname = document.getElementById(txtfirst)。value;

if(Firstname ==First Name|| Firstname == ){

alert(名字必须填写);

返回false;

}

else {

if(!Firstname.match(/ ^ [a-zA-Z] * $ /)|| Firstname.match(/ /)|| Firstname.match(/ @ /)| | Firstname.match(/ ^ [#$%^&*()!] /)){

alert(无效的名字);

返回false; < br $> b $ b}

}



   < asp:Button ID =signupbtnrunat =serverText =Sign uponclick =signupbtn_ClickOnClientClick =return Validateform(); Class =button/>

I have created 2webforms login and signup. And later i have created masterpage. I have included these to pages in masterpage.But the problem is that my validations in javascript are not working on masterpage..It is not displaying alert messages like "fill firstname" etc. and when run this form without masterpage all the validations are working.what is the solution to this problem.
here is some code :
<script type="text/javascript">
function Validateform() {
var Firstname = document.getElementById("txtfirst").value;
if (Firstname == "First Name" || Firstname == "") {
alert("Firstname must be filled out");
return false;
}
else {
if (!Firstname.match(/^[a-zA-Z ]*$/) || Firstname.match(/ /) || Firstname.match(/@/) || Firstname.match(/^[#$%^&*()!]/)) {
alert("Invalid firstname");
return false;
}
}

   <asp:Button ID="signupbtn" runat="server" Text="Sign Up" onclick="signupbtn_Click" OnClientClick="return Validateform();" Class="button" />

推荐答案

/)|| Firstname.match(/ /)|| Firstname.match(/ @ /)|| Firstname.match(/ ^ [#
/) || Firstname.match(/ /) || Firstname.match(/@/) || Firstname.match(/^[#


%^&*()!] /)){

alert(无效的名字);

返回false;

}

}



   < asp:Button ID =signupbtnrunat =serverText =Sign uponclick =signupbtn_ClickOnClientClick =return Validateform(); Class =button/>
%^&*()!]/)) {
alert("Invalid firstname");
return false;
}
}

   <asp:Button ID="signupbtn" runat="server" Text="Sign Up" onclick="signupbtn_Click" OnClientClick="return Validateform();" Class="button" />


当您实现母版页时,控件的ID将被更改。



所以,请尝试如下...

When you implement Master Pages, the id of controls would be changed.

So, try like below...
document.getElementById('<%= txtfirst.ClientID %>');


这篇关于javascript验证警告msgs未显示在母版页中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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