mrblah
mrblah

Reputation: 103517

Can a asp.net mvc view page have a webform control on it?

Can a asp.net mvc view page have a webform control on it?

I think I read about it before, but I'm not sure how it would work since MVC doesn't use viewstate etc?

Upvotes: 4

Views: 1504

Answers (4)

griegs
griegs

Reputation: 22760

Don't forget that MVC implements REST so ViewState is now pretty much obsolete unless you implement it yourself using say hidden fields.

About the only thing that the WebForm controls were good for was Ajax IMHO.

If you replace WebForm Controls with Partial Views, WebControl classes and jQuery plugins then you can achive the same.

I'm currently leaning towards writing my own WebControls and jQueryPlugins and referencing them within PartialViews.

There are heaps of jQuery plugins now available which perform pretty much all the actions that the WebForm controls did.

Upvotes: 1

Matt Hidinger
Matt Hidinger

Reputation: 1753

What I know for sure is that any control that implements IPostBackEventHandler or IPostBackDataHandler will fail automatically -- they will throw an exception saying you need a <form runat="server">

That said, you should avoid using ASP.NET WebForms server controls in your MVC applications.

Upvotes: 1

Keith Adler
Keith Adler

Reputation: 21178

Not most web controls because they depend on ControlState and in some cases ViewState. Third parties like Telerik are adapting their controls to get around this, however the long-term goal is for people to build new controls that are more built around standards like JavaScript, jQuery, JSON, etc.

Upvotes: 0

John Gietzen
John Gietzen

Reputation: 49544

It can, but the Viewstate is not available. So, If the control relies on the viewstate, it may malfunction.

Also, events will not be readily available.

Upvotes: 6

Related Questions