如何从后面的代码按特定顺序调用两个javascript函数 [英] How to call two javascript function in a particular sequence from code behind

查看:59
本文介绍了如何从后面的代码按特定顺序调用两个javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

在我的网页中,我有2个javascript函数
1. fillVC(隐藏div)
2. showDIV(显示div)

我想按顺序在按钮单击上调用两个不同的javascript函数
1. fillVC
2. showDiv

我尝试了以下操作:

Hello friends,

In my web page I hav 2 javascript function
1. fillVC (to hide div)
2. showDIV (to display div)

I want to call two different javascript function on button click in a sequence
1. fillVC
2. showDiv

I tried following:

protected void btnSearch_Click(object sender, EventArgs e)
   {
       this.GVDatabind();
       ClientScript.RegisterStartupScript(typeof(Page), "Javascript", "fillVC();", true);
       ClientScript.RegisterStartupScript(typeof(Page), "Javascript", "showDIV();", true);
   }



但问题是showDIV gets called before fillVC.

我已经用脚本写过:



but problem is showDIV gets called before fillVC.

I have written in script:

<script>
     function showDIV()
     {}
     function fillVC()
     {}
</script>



Does the sequence of writing the function plays role in call of function??

知道如何实现吗?



Does the sequence of writing the function plays role in call of function??

Any idea how to achieve this?

推荐答案

尝试一下
ClientScript.RegisterStartupScript(GetType(),"Open","Function Name",true);


为什么不将代码放在onClientClick的前端中.您可以在其中包含尽可能多的功能.
看看下面的例子

Why don''t you put that code in Front-End inside onClientClick.. you can include as many as functions there.
have a look at example below

<asp:button id="btnSubmit" text="Add Record" runat="server" tooltip="Click to Submit Filled Date" onclick="btnSubmit_Click" onclientclick="return ValidateEmail();CheckAge();ValidateForm(); " xmlns:asp="#unknown" />


Since javascript functions run in parallel fashion. fillVC() and showDIV() runs in parallel.

在fillVC()中,我曾经在末尾隐藏div,但在showDIV()中的语句执行结束之前就隐藏了.

因此div曾经用来隐藏.

解决方案:
I have put the code to hide the div on the first line in function and now the div is getting displayed as per the function call.

感谢您的支持.

希望这对有需要的人有所帮助:)
Since javascript functions run in parallel fashion. fillVC() and showDIV() runs in parallel.

In fillVC(), i used to hide div at the end but before that execution of statements in showDIV() ends.

So div used to get hide.

Solution:
I have put the code to hide the div on the first line in function and now the div is getting displayed as per the function call.

Thanks for your support friends.

Hope this helps the needy :)


这篇关于如何从后面的代码按特定顺序调用两个javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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