用asp按钮运行javascript的方式是什么? [英] What is the way to run the javascript with the asp buttons?

查看:82
本文介绍了用asp按钮运行javascript的方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查用户是否已填写必填字段,或者是否未单击SignUP按钮.但是实际上我不知道如何通过JavaScript做到这一点.

我的asp按钮ID是用户名,密码,电子邮件.这些是必填字段,当用户单击SignUp按钮时,它应检查是否已填写.如何通过使用asp.net的javascript完成此操作.

I want to check that user has fill the required fields or not on SignUP button click. But actually I don''t know how to do that through JavaScript.

My asp button ID''s are username, password, email. These are mandatory fields to fill when user click on SignUp button it should check that these are fill. How can I accomplish that through javascript with asp.net.

推荐答案

<script type="text/javascript">
function Validate()
{
    if(document.getElementById('<%=ddlCountry.ClientID%>').value=="0")
    {
        alert('Please Select Country');
        return false;
    }
   else if(document.getElementById('<%=ddlState.ClientID%>').value=="0")
    {
        alert('Please Select State');
        return false;
    }
   else if(document.getElementById('<%=txtcityName.ClientID%>').value=="")
    {
        alert('Please Enter City Name');
        return false;
    }
        return true;
}
</script>






按钮应该是这样的






button should be like this

<asp:button id="imbBtnSubmit" runat="server" onclick="imbBtnSubmit_Click" onclientclick="javascript:return Validate();" xmlns:asp="#unknown" />







您要这个脚本,我想请检查一下







you are asking for this script i think plz check this

function Validate()
{

var test="";
    if(document.getElementById(''<%=ddlCountry.ClientID%>'').value=="0")
    {
        
        test="country,";
        
    }
   if(document.getElementById(''<%=ddlState.ClientID%>'').value=="0")
    {
    test=test+"state,";
    
    }
   if(document.getElementById(''<%=txtcityName.ClientID%>'').value=="")
    {
      test=test+"city,";
       
    }
    if(test=="")
    return true;
    else
    {
    if(test.length>0)
    test= test.substr(0,test.length-1);
    alert(test +" field(s) are mandatory please fill those");
    return false;
    }
           
}


您可以将OnClientClick事件用作:
You can use OnClientClick event as:
<asp:button id="btn1" runat="server" onclick="btn1_Click" onclientclick="javascript:return fun();" xmlns:asp="#unknown" />



为此,请编写一个javascript函数:



for this write a javascript function:

function fun1()
{
if(document.getelementbyId(''<%=btn1.ClientId%>').value==0)
alert("Please Enter jkhkjhkj";
return false;
}


function Validation()
{
var userid=document.getElementById('<%=txtUserID.ClientID %>');
var pwd=document.getElementById('<%=txtPwd.ClientID %>');
var email=document.getElementById('<%=txtemail.ClientID %>');
if(userid.value=="")
{
alert("Please Enter UserID");
userid.focus();
return false;
}
if(pwd.value=="")
{
alert("Please Enter Password");
pwd.focus();
return false;
}
if(email.value=="")
{
alert("Please Enter Password");
email.focus();
return false;
}
}







<asp:button id="btnLogin" runat="server" text="SignUp" onclick="btnLogin_Click" onclientclick="javascript:return Validation();" xmlns:asp="#unknown" />


这篇关于用asp按钮运行javascript的方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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