如何停止重新加载页面点击按钮时? [英] How to stop to reload page when click the button?

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

问题描述

我有asp.net网站,其中包括按钮一些计算。当我preSS的按钮,我的计算工作正常,但首先网页正在刷新,然后计算看起来在标签上。我想这样做,计算看起来在标签上直接。而无需刷新。我给一些codeS。

P.S。此外Page_Load中具有接收每日汇率的函数

ASP

 < ASP:按钮的ID =Button1的=服务器背景色=#990000
 BORDERCOLOR =#333333前景色=白的onclick =的button1_Click文本=计算
 WIDTH =85px边框​​=开端的风格=保证金左:20像素
 的ValidationGroup =grup1/>

按钮单击

 保护无效的button1_Click(对象发件人,EventArgs的发送)
{
双sayi1,sayi2,sayi3,hesap,sonuc;sayi1 = Convert.ToDouble(Tb1.Text);
sayi2 = Convert.ToDouble(Tb2.Text);
sayi3 = Convert.ToDouble(Tb3.Text);
如果(Tb1.Text.Contains(。)|| Tb2.Text.Contains(。)|| Tb3.Text.Contains(。))
{
  ...
  ...
  ...


解决方案

使用Ajax的。如果没有,你总是会调用回发事件。或在另一方面做一些客户端编程的JavaScript。

I have asp.net website which include some calculation on button. When I press the button, my calculation works fine but, firstly page is refreshing and then the calculation looks on the label. I want to do that calculation looks on the label directly. Without refreshing. I give some codes.

p.s. Also Page_Load has a function that receives daily exchange rates

ASP

<asp:Button ID="Button1" runat="server" BackColor="#990000" 
 BorderColor="#333333" ForeColor="White" onclick="Button1_Click" Text="Calculate" 
 Width="85px" BorderStyle="Outset" style="margin-left: 20px" 
 ValidationGroup="grup1" />

BUTTON CLICK

protected void Button1_Click(object sender, EventArgs e)
{
double sayi1, sayi2, sayi3, hesap, sonuc;

sayi1 = Convert.ToDouble(Tb1.Text);
sayi2 = Convert.ToDouble(Tb2.Text);
sayi3 = Convert.ToDouble(Tb3.Text);


if (Tb1.Text.Contains(".") || Tb2.Text.Contains(".") || Tb3.Text.Contains("."))
{
  ...
  ...
  ...

解决方案

Use Ajax. If not you will always invoke a postback event. Or on the other hand do some client side programming with javascript.

这篇关于如何停止重新加载页面点击按钮时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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