且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何停止重新加载页面点击按钮时?

更新时间:2023-12-02 23:05:46

使用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.