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?
views:
50answers:
2
+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
2009-03-11 10:08:34
How do I reference childcontrols of that control?
Niels Bosma
2009-03-11 20:29:44
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
2010-02-10 21:24:52
+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
2009-03-11 10:14:59