Asp.net include snippets vs using labels
I'm a big Django user for web development, and I've grown to love the separation of code and display that popular template engines allow for (not just Django). I'm starting some Asp.net work and I'm trying to learn the best ways to do certain things that I'm used to doing with Django.
What I want to do is separate some logic into another file that could be used in several places. What I would have done in Django is create a "s开发者_如何学编程nippet.html" file that just had some template logic in it that could be included in other pages as long as the context it expected was there in the parent page. In Asp.net it seems something I could do is use a label and set the label.Text value to something when I want to put in that logic, but then I start doing HTML in C# and that is something I want to avoid at all costs. I can't seem to find a good idiom for separating a little chunk of asp.net logic into another file that can be included at will.
What are my options?
Thanks.
The ASP.NET equivalent is a user control:
In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls using the same techniques you use for creating ASP.NET Web pages. These controls are called user controls.
A user control is a kind of composite control that works much like an ASP.NET Web page—you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.
Are you using ASP.NET web forms or ASP.NET MVC? ASP.NET MVC will be a much smoother transition for you if you are used to Django.
精彩评论