Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Ajax UpdatePanel

I know (at least i'm pretty sure) there isn't a control for MVC like the asp:UpdatePanel. Can anyone give me some idea on how to do this.

I have a collection that i add entries to from my repository & services layers. in my masterpage i would like to show an alert depending on if there is anything in this collection.

Normally i would have an UpdatePanel whose UpdateMode="Always" and it would check the collection and display my messages.

Do you know how i can achieve something similiar in MVC?

like image 627
Dacrocky Avatar asked Mar 04 '09 17:03

Dacrocky


People also ask

What is UpdatePanel Ajax?

Introduction. UpdatePanel controls are a central part of AJAX functionality in ASP.NET. They are used with the ScriptManager control to enable partial-page rendering. Partial-page rendering reduces the need for synchronous postbacks and complete page updates when only part of the page has to be updated.

Can we use update panel in MVC?

With MVC you are rendering your Html stream much more directly than the abstracted/pseudo-stateful box that WebForms wraps you up in. Of course UpdatePanel can be used in much more complex scenarios than this (it can contain INPUTS, supports ViewState and triggers across different panels and other controls).

What is UpdatePanel control?

UpdatePanel controls work by specifying regions of a page that can be updated without refreshing the whole page. This process is coordinated by the ScriptManager server control and the client PageRequestManager class. When partial-page updates are enabled, controls can asynchronously post to the server.

What is postback trigger in UpdatePanel?

Description. <asp:AsyncPostBackTrigger> Specifies a control and event that will cause a partial page update for the UpdatePanel that contains this trigger reference.


1 Answers

Stay away from the UpdatePanel concept all together.

ASP.NET MVC includes jQuery, which is fully supported by Microsoft now. You will want to create partial views (RenderPartial) that make calls back to a method on a controller, that returns JSON.

Then, use jQuery to wire up the control and partial views.

jQuery is an extremely powerful javascript library. I highly recommend the book jQuery in Action as a reference when diving into the ASP.NET MVC /Scripts/jquery-x.x.x.js files. :)

like image 80
eduncan911 Avatar answered Sep 19 '22 18:09

eduncan911