在页面加载时从VB代码调用JS

时间:2014-03-28 12:37:08

标签: jquery asp.net

我正在开发一个asp.net项目,其中通过VB代码调用数据库。在成功请求后,div必须通过JQuery保留。

例如

VB代码:

    If Confirmationcode = Passcode.text Then
        'Perform the animation here   ...   NextPage();
        'Registerstartupscript doesnt work as this is not in the page_load event
         Response.Redirect("Default.aspx", False)
    End If

JS:

    <script type="text/javascript">
    function NextPage() {
        $('.Wrapper').animate({ left: '-150%' }, 800);
    };
    </script>

这很简单:

必须执行动画,一旦完成,则必须加载新的aspx页面。

1 个答案:

答案 0 :(得分:0)

所以基本上你不应该使用Response.Redirect来解决这种情况,因为你想首先执行jQuery,然后只有页面应该重定向。

尝试这样的事情:

VB代码:

If Confirmationcode = Passcode.text Then
    'Perform the animation here   ...   NextPage();//don't do this
     int flagAnimate = true;//set one flag here instead which will tell us whether to  animate the div or not
    'Registerstartupscript doesnt work as this is not in the page_load event//not needed
     //Response.Redirect("Default.aspx", False) //no need to redirect from here
End If

<强> JS:

<% if(flagAnimate == true){ %>
  <script type="text/javascript">
  //perform your animation here
    function NextPage() {
      $('.Wrapper').animate({ left: '-150%' }, 800);
    };  
    NextPage();//by calling this function
   //and then redirect the page by using the following code
   self.location.href='/Default.aspx'
  </script>
<% } %>