Version 1, last updated by Andrew Davey at September 01, 2009 09:02 UTC

So you have piece of HTML that you want to reuse? And it depends on some data?

So you're saying you want a thing that given data as input provides HTML as output? Hmm, sounds like a function to me!

That's right, good old functions. Easy to write, easy to test!

Use VB Modules to package up functions. This makes them static and callable by their name, with no messy Class prefix.

Module MyControls

    Function CustomerInfo(ByVal name As String) As XElement
        Return <div>Customer Info: <%= name %></div>
    End Function

End Module

Use like this:

<div>
    <h1>Customers</h1>
    <%= CustomerInfo("Andrew") %>
    <%= CustomerInfo("Bob") %>
    <%= CustomerInfo("Chris") %>
</div>

Freaking easy eh?!

You can break apart a complex view class into functions (just like with regular code refactoring). You can keep those functions in the view class if they are only used there.