Guest
Guest

Reputation: 275

How to avoid page refreshing after button click

I've this problem for 3 days and I couldn't find the real answer. I want that if I click a button the code will run and not to refresh all the page. For example:

ASPX code

<dx:ASPxButton ID="ASPxButton1" runat="server" Text="New" OnClick="ASPxButton1_Click"></dx:ASPxButton>
<dx:ASPxButton ID="ASPxButton2" runat="server" Text="Delete"></dx:ASPxButton>

CS code

protected void ASPxButton1_Click(object sender, EventArgs e) //new button
{
    ASPxButton2.Enabled = false;
}

That's basicly what I want to do. Click the new button and make the delete button enabled false without refreshing all the page.

What I tried:

<dx:ASPxButton ID="ASPxButton1" runat="server" Text="New" OnClick="ASPxButton1_Click" onclientClick=" return false;"></dx:ASPxButton>
<asp:button ID="Button1" runat="server" Text="New" OnClick="Button1_Click" onclientClick=" return false;"></asp:button>
<asp:button ID="Button1" runat="server" Text="New" OnClick="Button1_Click"></asp:button>
<asp:button ID="Button1" runat="server" Text="New" OnClientClick="DisableButton(); return false; "></asp:button>

function DisableButton() {
  document.getElementById("<%= ASPxButton2.ClientID %>").click();
}

Tried UpdatePanel too but I use MasterPage and that's why it doesn't work.

Upvotes: 2

Views: 5917

Answers (2)

Koce
Koce

Reputation: 116

Put AutoPostBack="false" on your ASPxButton1. By default it's true.

<dx:ASPxButton ID="ASPxButton1" AutoPostBack="false" runat="server" Text="New" OnClick="ASPxButton1_Click">
</dx:ASPxButton>
<dx:ASPxButton ID="ASPxButton2" runat="server" Text="Delete"></dx:ASPxButton>

Upvotes: 1

Paolo Falomo
Paolo Falomo

Reputation: 447

You should Use event.preventDefault() Javascript Function

Here is an example.

function DisableButton(event){
  event.preventDefault();
}
<a href="www.google.it">This goes to google!</a>
<a OnClick="DisableButton(event)" href="http://www.google.it">And this one don't!</a>

Upvotes: 2

Related Questions