tags:

views:

50

answers:

2

Is it possible to sepparate 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?

+2  A: 

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"
%>
Spikolynn
How do I reference childcontrols of that control?
Niels Bosma
If in your .ascx file you have a control <asp:Label id="label" runat="server" />In control code define protected Label myLabel, then set myLabel.Text = "x" for instance.
Spikolynn
+2  A: 

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.

Marc Gravell