Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to avoid postback when i click the button in MVC

I have two button in my cshtml page. When i click the first button data fetch from the database and bind it my controls. The records are many so the second button goes down, then i click the second button same thing happened fetch from the database and bind the grid, so the page is loaded then the page goes up. I want to stay same place when i click the second button. How to prevent it.

like image 794
Lawrence Avatar asked Feb 12 '23 10:02

Lawrence


1 Answers

make your button like this :

<input type="button" id"button2" onclick="CallAjax();return false;"/>

//then in javascript

function CallAjax()
{

//your ajax call here to retrieve or update data

}
like image 176
Adam Avatar answered Feb 14 '23 23:02

Adam