[英]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.