0

I want to stop page refresh on ajax call.I have created multiple view and those view gets open when user clicks on link button from tree view.

On each button click view gets open after page refresh.I want to put loading image icon when user clicks on button and stop page refresh and display the data.

Can someone please help me with this issue?

Tree View :

<ul>
   <li>
      <asp:LinkButton runat="server" OnClientClick="DisplayLoadingDiv()"  ID="Button1" Text="Add Institute" OnClick="Button1_Click" />
   </li>

Server Side Code :

protected void Button1_Click(object sender, EventArgs e)
    {            
        MultiView1.Visible = true;
        MultiView1.SetActiveView(View1);
    }
vimal mishra
  • 1,087
  • 2
  • 12
  • 32
  • 3
    show the codezz – BenG Sep 21 '16 at 19:37
  • 1
    Ajax doesn't cause a page refresh on its own. If it's triggered by a button press or link click, then you'll need to use `event.preventDefault();` to stop the usual page-changing behaviour (`event` would be the first argument received by an event listener). – Whothehellisthat Sep 21 '16 at 19:39
  • @Whothehellisthat Thanks for the reply.protected void Button1_Click(object sender, EventArgs e) { MultiView1.Visible = true; MultiView1.SetActiveView(View1); } is my code .I am not able to put e.preventDefault(); can u please help me where and how to use it.I am new to this. – vimal mishra Sep 21 '16 at 19:46
  • @BenG I have updated the question with code.Thanks!! – vimal mishra Sep 21 '16 at 19:51
  • Okay. Do you have the Ajax stuff already sorted? – Whothehellisthat Sep 21 '16 at 20:03
  • Looks like there's another post about stopping the postback from a LinkButton: [SO](http://stackoverflow.com/questions/16710561/prevent-linkbutton-post-back-onclientclick-not-working-why) – Whothehellisthat Sep 21 '16 at 20:04
  • @Whothehellisthat Yeah I think I dont have any issue in ajax.I am able to make ajax call and get the data properly and display. – vimal mishra Sep 21 '16 at 20:15
  • Cool. Did that link help? – Whothehellisthat Sep 21 '16 at 20:15

1 Answers1

1

If you are using the WebForm structure from ASP.net your content is wrapped whithin a form. Every button on your page will submit this form. You can use jQuery to prevent the form to be submitted:

$( "#yourFromID" ).submit(function( event ) {
  alert( "Handler for .submit() called." );
  event.preventDefault();
});

Then your ajax call will work as desired

Dranes
  • 156
  • 10
  • Thanks for the reply.I am sorry I used this code but page refresh didn't stop and alert didn't popup.Can you please suggest me what to do. – vimal mishra Sep 23 '16 at 20:48