After several years of PHP programming; using several different frameworks from home-grown till CodeIgniter and Zend, I changed to developing with C# and a bit Java. A nice change, the syntax sugar provided by both languages is great!
ASP.NET provides us with User Controls, Pages and MasterPages; which makes it easy enough to create a nice degree of concern separation. The major nuisance while working with this non-MVC method is you've to find all runat server controls within for instance an PlaceHolder Control.
See the next code example: {syntaxhighlighter brush:c#} // Template file (.aspx) // Code file (.cs) System.Web.Ui.Controls.Literal literalMyLiteral = placeholderMyPlaceHolder.FindControl("literalMyLiteral") as System.Web.Ui.Controls.Literal; literalMyLiteral.Text = "Fubar"; {/syntaxhighlighter}
There're dozens of solutions to this situation; you could write yourself a extended PlaceHolder control, accept the way it works, change to the ASP.NET MVC method or write yourself a handy helper function such as {syntaxhighlighter brush:c#} protected System.Web.UI.Controls.Literal findLiteral(String p_stringBasename, System.Web.UI.Control p_webUIControl) { return p_webUIControl.FindControl("literal" + p_stringBasename) as System.Web.UI.Controls.Literal; } {/syntaxhighlighter}
With even a minor bit of work you could provide each Page Instance, MasterPage Instance, User Control Instance with those functions through a bit of inheritance in order to make it possible to just simply write code such as {syntaxhighlighter brush:c#} findLiteral("MyLiteral", placeHolderMyPlaceHolder).Text = "Fubar"; {/syntaxhighlighter}
Less = more stays my motto ... I'm curious towards how you guys have solved the same trouble ... Extending and inheriting the basic ASP.NET User Controls makes for way to much work and is to unreadable in my eyes ... I preferably use the MVC Framework ASP.NET provides but for now I'm stuck with working directory with all those components.