I am writing an application that requires that my customer can layout their input forms in which ever way they choose.
I would like to use an HTML template with placeholders, and then replace these with secified .NET controls at runtime:
<table style='width: 100%;'> <tr> <td colspan='2'> <fieldset title='Customers Template' > <table style='width:100%;'> <tr> <td width='140'> Policy Number:</td> <td width='150'> $$Policy Number$$</td> <td colspan='2' rowspan='3' valign='top'> Type 1:<br /> $$Type 1$$</td> <td rowspan='3' valign='top'> Info:<br /> $$Info$$</td> <td rowspan='3' valign='top'> Problems:<br /> $$Problems$$</td> </tr>...
So I want to find and replace my $$xxx$$ text with various .NET controls, depending on the datatype of the field being added, at runtime.
Any suggestions on good ways to approach this?
Thanks, Mark
Replace your $$xxx$$ blocks with
<asp:PlaceHolder>controls.At runtime you can parse the template
— In the most simplest case, you can require the template be valid xhtml, then you can simply use the .NET XML APIs to iterate through all the ChildNodes of the XmlDocument. From each element build the appropriate ASP.NET Server control.
For a more complex (and complete HTML parser) see http://www.developer.com/net/csharp/article.php/2230091
As you parse, wherever you see
<asp:PlaceHolder>– replace that with your logic that defines your template.Tutorial: http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=752