PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Can we user webform usercontrols or server controls in MVC?

 
 
Allan2010
Guest
Posts: n/a
 
      5th May 2010
Hi,

Can we use webform usercontrols (ascx files) in an MVC application?

Generally, is there any online guide that explains best practices when/how
webfoms and MVC could be integrated and co-exist?

Thank you,
Allan


 
Reply With Quote
 
 
 
 
Mr. Arnold
Guest
Posts: n/a
 
      5th May 2010
Allan2010 wrote:
> Hi,
>
> Can we use webform usercontrols (ascx files) in an MVC application?


A Web usercontrol would have its own MVC implementation, like a Web form
would have its own MVC implementation. If a usercontrol was accessing
data from a database, then it would use its MVC logic (separate logic)
like the Web form using its MVC logic to access the database that is
hosting the usercontrol, based on business rules used by each MVC
controller.

>
> Generally, is there any online guide that explains best practices
> when/how webfoms and MVC could be integrated and co-exist?
>


Maybe, you don't fully understand what the MVC design pattern is about.

What is Model –View- Controller?

(MVC) is an architectural pattern used in software engineering.
Successful use of the pattern isolates business logic from user
interface considerations,
resulting in an application where it is easier to modify either the
visual appearance
of the application or the underlying business rules without affecting
the other.
In MVC, the model represents the information (the data) of the application;
the view corresponds to elements of the user interface such as text,
checkbox items,
and so forth; and the controller manages the communication of data and the
business rules used to manipulate the data to and from the model.

http://en.wikipedia.org/wiki/Model-view-controller

The best practice is keep the UI dumb. The UI passes controls to the
'controller' through the 'view' where the controller works with the
controls to populate or extract data from the controls, based on
business rules.

You either start off using MVC for the project or you convert an
existing project to use MVC fully. It's either all or nothing in either
case.

However, for a given form or usercontrol, one may not be able to
implement MVC, which is based on a control's behavior of not working or
not being rendered using MVC. If this is the case, then things with a
control must be done at the UI at form or usercontrol level, which is
rare and mainly happens with 3rd party controls.


I don't use MVC myself. I use MVP which can be used for a Windows form
or a Web form application.

What is Model –View- Presenter?

MVP is a software pattern considered a derivative of the
Model-view-controller.

http://en.wikipedia.org/wiki/Model_View_Presenter



 
Reply With Quote
 
Zhi-Qiang Ni[MSFT]
Guest
Posts: n/a
 
      5th May 2010
Hi Allan,

The two kinds of user control is different.
The user control in webform is of type System.Web.UI.UserControl while the
one in MVC is of type System.Web.Mvc.ViewUserControl which is inherited
from System.Web.UI.UserControl.
Generally speaking, we need to import the following statement in page to
define a mvc uer control .

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

Besides there is no code behind for MVC user control and no any server
control conception for MVC.

If you want to mix the traditional ASP.NET and the ASP.NET MVC, you can
take a look at the following articles.
http://www.packtpub.com/article/mixi...nd-asp.net-mvc

http://blogs.imeta.co.uk/MGodfrey/ar...03/31/663.aspx

--
Sincerely,
Zhi-Qiang Ni
Microsoft Online Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================

 
Reply With Quote
 
Cubaman
Guest
Posts: n/a
 
      6th May 2010
On May 5, 2:38*am, "Allan2010" <Alan2...@nospam.nospam> wrote:
> Hi,
>
> Can we use webform usercontrols (ascx files) in an MVC application?
>
> Generally, is there any online guide that explains best practices *when/how
> webfoms and MVC could be integrated and co-exist?
>
> Thank you,
> Allan


Hello:
An MVC form don't have a runat="server" tag, MVC page cicle is
completely different from classic asp.net. So, the short answer is no,
you can't use regular asp.net server controls in MVC pages.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User controls - Is there a max per webform? Dblood Microsoft ASP .NET 0 23rd Jun 2005 04:46 PM
NEWBIE - Server Controls in User Controls Dave Microsoft ASP .NET 0 29th Nov 2004 08:06 PM
Invisible WebForm Server controls in ASP.NET form - H E L P ! tommy Microsoft ASP .NET 5 14th Jan 2004 04:31 PM
RE: Cycle through UserControls on webform. Russell Gibson Microsoft Dot NET 0 7th Aug 2003 09:31 AM
Problem when Hosting Windows User controls in Webform news.microsoft.com Microsoft ASP .NET 2 8th Jul 2003 03:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:40 PM.