This project is read-only.

Using control from ASCX file

XsltDb is capable to create and manipulate ASP.NET controls. If you have a user control in the form of ASCX file - you can put it on the DotNetNuke page.
I show you how to complete that by using TextEditor.ascx as an example control.

First, we have to declare a prefix.

<xsl:text disable-output-escaping="yes"><![CDATA[
<%@ Register TagPrefix="dnn" TagName="Editor" Src="~/Controls/TextEditor.ascx" %>
Here we tell the ASP.NET engine that control file has Controls/TextEditor.ascx virtual path and we want to use dnn:Editor tag to put this control on a page. After that we are ready to create instance of the control.

<mdo:asp xmlns:dnn="dnn">
  <dnn:Editor runat="server" />
mdo:asp tag is required as a container to prevent namespaces from appearing inside. This allows XSLT not to declare namespaces at each resulting markup node.

The following example shows how get text from the editor on server side and save it to database.

<xsl:text disable-output-escaping="yes"><![CDATA[
<%@ Register TagPrefix="dnn" TagName="Editor" Src="~/Controls/TextEditor.ascx" %>

<mdo:asp xmlns:asp="asp" xmlns:dnn="dnn">
  <asp:Label runat="server" ID="lResult" />
  <dnn:Editor runat="server" ID="txt" />
  <asp:Button runat="server" ID="btnSave" Text="Save" />

  <xsl:if test="mdo:event-source()='btnSave'">
    <xsl:variable name="txt" select="mdo:aspnet('#txt.Text')"/>
    <!-- Here you can save text to the database
    <xsl:execute select="mdo:sql('insert texts(txt) values(@txt)', '$script', '@txt', $txt)" />
    <xsl:execute select="mdo:assign('#lResult.Text', concat('HTML saved: ', $txt))" />
As far as we are using ASP.NET control we have to put all code accessing properties of control into the asp:pre-render tag. This XSLT is executed in PreRender ASP.NET page handler and we can be sure that controls are already created. If we put our code out of the mdo:pre-render it will be called before controls are created and their state is loaded and as result module would fail.
  • mdo:aspnet allows us to access many of ASP.NET objects in the context of the request. It accepts a property path as an argument. the first name ni the path is predefined name of object. if this name is started with "#" - XsltDb uses it as an ID of ASP.NET control, so we are capable to access controls' properties inside current module.
  • mdo:assign allows us to assign properties of ASP.NET object. It accepts property path in the same way as mdo:aspnet. The second parameter is a value that will be written to the property specified.
In comment block you can find an mdo:sql function that executes SQL statement that put the text into tha database table.

Last edited Jun 25, 2010 at 12:15 PM by findy, version 3


No comments yet.