停止ASP.NET按钮的页面重载 [英] Stop page reload of an ASP.NET button

查看:256
本文介绍了停止ASP.NET按钮的页面重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET应用程序,我已经插入了一个按钮调用JavaScript函数(的OnClientClick 事件)和VB.NET功能(的OnClick 事件)

NET application, I have inserted a button that call a Javascript function (OnClientClick event) and a VB.NET function (OnClick event)

<asp:Button OnClientClick="jsfunction() " OnClick="vbfunction" Text="Submit" runat="server" />

问题是,当我按一下按钮,它刷新页面,并删除文本框的内容。

The problem is that when I click the button, it refreshes the page and delete the content of the text boxes.

我曾尝试与插入返回false; OnClienClick 事件,但它不执行的OnClick事件。

I have tried with inserting return false; on the OnClienClick event, but it doesn't execute the OnClick Event.

我如何避免页面重载?

PS:在的JavaScript函数结束时打开一个新窗口 window.open(newWindow.aspx),但我想,第一个页面插入十个分量的价值通过在文本框中用户。

P.S.: At the end of the Javascript function a new window is opened window.open(newWindow.aspx), but I want that the first page mantain the value inserted by the user in the Text Boxes.

在此先感谢:)

推荐答案

您需要在两点使用return语句。

You need to use return statement at two points.

OnClientClick="return jsfunction();"

function jsfunction()
{
  //
  return false;
}

您可以在函数调用这样后返回false。

OnClientClick="jsfunction(); return false;"

注意如果你想要做回发有条件那么你就需要返回true或false。

Note if you want to do postback conditionally then you need to return true or false.

OnClientClick="return jsfunction();"

function jsfunction()
{
  if(conditionForPostBack)
      return true;
  else
      return false;
}

这篇关于停止ASP.NET按钮的页面重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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