简体   繁体   English

如何在asp.net中的客户端单击事件上调用2个javascript

[英]how to call 2 javascript on client click event in asp.net

I am trying to call 2 javascript one time on client click event. 我试图在客户端点击事件上一次调用2个javascript。 I am only able to call them one of the javascript. 我只能称他们为JavaScript之一。 Once the user clicks the button, i want to call 2 javascript because each javascript is checking 2 diferent gridviews. 用户单击按钮后,我要调用2个javascript,因为每个javascript正在检查2个不同的gridview。 How can i call both of them one time on client click event. 我如何一次在客户端单击事件上将它们都调用。 Here is my button 这是我的按钮

 <asp:LinkButton ID="btn_Submit" runat="server" CssClass="btn btn-primary" OnClientClick="return validate_1();" OnClick="btn_Submit_Click"> 
     <i aria-hidden="true" class="glyphicon glyphicon-ok"></i>Submit
     </asp:LinkButton>

here is the 1st one: 这是第一个:

<script type="text/javascript">
        function validate_1() {
            var flag = true;
            var dropdowns = new Array(); //Create array to hold all the dropdown lists.
            var gridview = document.getElementById('<%=Main_GV.ClientID%>'); //GridView1 is the id of ur gridview.
            dropdowns = gridview.getElementsByTagName('Select'); //Get all dropdown lists contained in GridView1.
            for (var i = 0; i < dropdowns.length; i++) {
                if (dropdowns.item(i).value == 'Select') //If dropdown has no selected value
                {
                    flag = false;
                    break; //break the loop as there is no need to check further.
                }
            }
            if (!flag) {
                alert('Warning.....  Thanks');
                document.getElementById('<%=btn_Submit.ClientID%>').style.visibility = 'hidden';
            }
            return flag;         

        }
    </script>

here is the 2nd one 这是第二个

<script type="text/javascript">

        function validate_2() {

            var f = document.getElementById('<%=GV_Test.ClientID%>');
            for (var i = 0; i < f.getElementsByTagName("input").length ; i++) {
                if (f.getElementsByTagName("input").item(i).type == "text") {

                    if (f.getElementsByTagName("input").item(i).value == 0) {
                        alert("warning....");
                        f.getElementsByTagName("input").item(i).focus();
                        return false;
                    }

                }

            }
        }
    </script>

i want to call both validate_1() and validate_2(). 我想同时调用validate_1()和validate_2()。 Thanks 谢谢

how about : 怎么样 :

return OnClientClick="return validate_1() && validate_2();"

If validate_1 doesn't pass then validate_2 will not get called. 如果validate_1不通过,则不会调用validate_2。 So if both functions return truthy, then your postback will take place. 因此,如果两个函数都返回true,则将进行回发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在asp.net中按钮点击事件调用之前和之后调用javascript函数 - How to call a javascript function before and after button click event call in asp.net 如何在 Asp.Net MVC 中的复选框单击事件上调用 JavaScript function - How to Call JavaScript function on checkbox click event in Asp.Net MVC 如何从 asp.net 按钮点击事件中调用 javascript function - How to call javascript function from asp.net button click event 如何从ASP.NET中的JavaScript触发按钮单击事件 - How to fire a button click event from JavaScript in ASP.NET 如何从JavaScript执行asp.net按钮单击事件? - How to execute asp.net button click event from JavaScript? 如何在asp.net中编写调用asp.net按钮click()事件的javascript函数? - How to write the javascript function calling the asp.net button click() event in asp.net? asp.net提交按钮单击事件处理程序完成后无法调用Javascript - unable to call Javascript after asp.net submit button click event handler is completed jQuery-在Asp.Net的客户端中调用服务器端事件 - JQuery - Call server side event in client side in Asp.Net 如何从asp.net中的代码引发客户端“重置”按钮的点击事件? - How to raise click event of a client side `reset ` button from code behind in asp.net? 如何使用asp.net在客户端单击上调用Java脚本 - how to call java-script on client click using asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM