Niels Bosma
Niels Bosma

Reputation: 11498

ASP.NET/UserControls: How do I separate the "controller" from the "view"?

Is it possible to separate the ascx ("view") and the ascx.cs ("controller") pars of a user control. Id like to move the controller part to App_Code to be resued while the view part is changed between projects?

Upvotes: 1

Views: 74

Answers (2)

Marc Gravell
Marc Gravell

Reputation: 1062540

In regular ASP.NET, even if you separate the code-behind and the ascx - they are still tightly coupled. It isn't a true "controller" (as separate from a view).

If you want this purity, consider ASP.NET MVC, which (obviously) addresses this in a different way.

Upvotes: 2

Spikolynn
Spikolynn

Reputation: 4173

Yes, write the codebehind in some service class which extends UserControl, and in your .ascx file inherit that class

<%@ Control
Language           = "C#"
Inherits           = "Project.Business.Service.MyControl"
%>

Upvotes: 2

Related Questions