[Xsltforms-support] XSLTForms with ASP.NET
Brought to you by:
alain-couthures
From: William D. V. <wi...@bi...> - 2011-12-16 21:11:22
|
Hi XForms fans! I just saved tons of work using XForms instead of WebForms in a .NET project I´m currently working. It's pretty easy to include an XForms in a ASP.NET page using XSLTForms and the asp:Xml Control for a server side transform. This line does the trick: <asp:Xml ID="Xml1" runat="server" DocumentSource="~/myform.xforms" TransformSource="~/xsltforms/xsltforms.xsl" EnableViewState="False" ></asp:Xml> And to process the submission with DOM, two lines do the work: <%@ Page Language="C#" %> <% System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(Request.InputStream); // process your xml here.... %> There is just two things to keep in mind: 1. You need the latest version of XSLTForms from the repository (I tested with rev 521). Previous versions don´t work with .NET transformation engine. 2. ASP.NET WebForms wraps all the controls in the page with <form >...</form> so when the Xml Control renders the xhtml for the XForm, clicking in the xf:triggers post the form submission (an undesirable behavior) because they are rendered as <button> with the default type=submit. There are to workarounds: 1. Move the <asp:Xml> outside the <form runat="server"> tag in the aspx page, 2. When that isn't possible (for example, when you use MasterPages), make a little modification in xsltforms.xsl to add the atributte type="button" when triggers are rendered. This is done in this template (line 1141 in rev 521): <xsl:template match="xforms:trigger|xforms:submit" ... Below is the generation of the <button> tag (line 1162 in rev 521): <button> <xsl:copy-of select="$innerbody"/> </button> You can add the attribute this way: <button> <xsl:attribute name="type">button</xsl:attribute> <xsl:copy-of select="$innerbody"/> </button> I know monsieur Alain kindly will include this change in a future release ;-) I'm getting mixed reaactions from my co-workers (most of them are MS fans), so I asked them to write a form using the normal aspnet way to calculate an invoice, allowing users to add details lines, sum totals, taxes, etc. They had to write more than 50 tricky lines of code, with events handlers, javascript and a lot of Googling. Then I showed it with XForms: five xf:bind and two xf:trigger for custom logic No need to say they are starting to get convinced. Merry Christmas, William Velasquez |