<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Nesterovsky bros - ASP.NET</title>
    <link>http://www.nesterovsky-bros.com/weblog/</link>
    <description />
    <language>en-us</language>
    <copyright>Nesterovsky bros</copyright>
    <lastBuildDate>Mon, 13 May 2013 23:09:02 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.12105.0</generator>
    <managingEditor>contact@nesterovsky-bros.com</managingEditor>
    <webMaster>contact@nesterovsky-bros.com</webMaster>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p style="direction: ltr">
Although WCF REST service + JSON is outdated comparing to Web API, there are yet a
lot of such solutions (and probably will appear new ones) that use such "old"
technology. 
</p>
        <p>
One of the crucial points of any web application is an error handler that allows gracefully
resolve server-side exceptions and routes them as JSON objects to the client for further
processing. There are dozen approachesin Internet that solve this issue  (e.g. <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;url=http%3a%2f%2fblog.manglar.com%2fhow-to-provide-custom-json-exceptions-from-as-wcf-service%2f">http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/</a>),
but there is no one that demonstrates error handling ot the client-side. We realize
that it's impossible to write something general that suits for every web application,
but we'd like to show a client-side error handler that utilizes JSON and KendoUI.
</p>
        <p style="direction: ltr">
On our opinion, the successfull error handler must display an understandable error
message on one hand, and on the other hand it has to provide technical info for developers
in order to investigate the exception reason (and to fix it, if need):
</p>
        <table border="0">
          <tr>
            <td style="vertical-align: top;">
              <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fimages%2fcolapsed-error-dialog.png">
                <img src="http://www.nesterovsky-bros.com/images/thumb-colapsed-error-dialog.png" alt="collapsed error dialog" />
              </a>
            </td>
            <td>
              <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fimages%2fexpanded-error-dialog.png">
                <img src="http://www.nesterovsky-bros.com/images/thumb-expanded-error-dialog.png" alt="collapsed error dialog" />
              </a>
            </td>
          </tr>
        </table>
        <p>
You may <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fErrorHandling.zip">download
demo project here</a>. It contains three crucial parts:
</p>
        <ul>
          <li>
A server-side error handler that catches all exceptions and serializes them as JSON
objects (see <strong>/Code/JsonErrorHandler.cs</strong> and <strong>/Code/JsonWebHttpBehaviour.cs</strong>).</li>
          <li>
An error dialog that's based on user-control defined in previous articles (see <strong>/scripts/controls/error.js</strong>,<strong> /scripts/controls/error.resources.js</strong> and <strong>/scripts/templates/error.tmpl.html</strong>).</li>
          <li>
A client-side error handler that displays errors in user-friendly's manner (see <strong>/scripts/api/api.js</strong>,
method <strong>defaultErrorHandler()</strong>).</li>
        </ul>
        <p>
Of course this is only a draft solution, but it defines a direction for further customizations
in your web applications.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f" />
      </body>
      <title>Error handling in WCF based web applications</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/05/13/ErrorHandlingInWCFBasedWebApplications.aspx</link>
      <pubDate>Mon, 13 May 2013 23:09:02 GMT</pubDate>
      <description>   &lt;p style="direction: ltr"&gt;
Although WCF REST service + JSON is outdated comparing to Web API, there are yet a
lot of such solutions (and probably will appear new ones) that use such &amp;quot;old&amp;quot;
technology. 
&lt;/p&gt;
&lt;p&gt;
One of the crucial points of any web application is an error handler that allows gracefully
resolve server-side exceptions and routes them as JSON objects to the client for further
processing. There are dozen approachesin Internet that solve this issue&amp;nbsp; (e.g. &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;amp;url=http%3a%2f%2fblog.manglar.com%2fhow-to-provide-custom-json-exceptions-from-as-wcf-service%2f"&gt;http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/&lt;/a&gt;),
but there is no one that demonstrates error handling ot the client-side. We realize
that it&amp;#39;s impossible to write something general that suits for every web application,
but we&amp;#39;d like to show a client-side error handler that utilizes JSON and KendoUI.
&lt;/p&gt;
&lt;p style="direction: ltr"&gt;
On our opinion, the successfull error handler must display an understandable error
message on one hand, and on the other hand it has to provide technical info for developers
in order to investigate the exception reason (and to fix it, if need):
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tr&gt;
&lt;td style="vertical-align: top;"&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fimages%2fcolapsed-error-dialog.png"&gt; &lt;img src="http://www.nesterovsky-bros.com/images/thumb-colapsed-error-dialog.png" alt="collapsed error dialog" /&gt; &lt;/a&gt; 
&lt;/td&gt;
&lt;td&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fimages%2fexpanded-error-dialog.png"&gt; &lt;img src="http://www.nesterovsky-bros.com/images/thumb-expanded-error-dialog.png" alt="collapsed error dialog" /&gt; &lt;/a&gt; 
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;
You may &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fErrorHandling.zip"&gt;download
demo project here&lt;/a&gt;. It contains three crucial parts:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
A server-side error handler that catches all exceptions and serializes them as JSON
objects (see &lt;strong&gt;/Code/JsonErrorHandler.cs&lt;/strong&gt; and &lt;strong&gt;/Code/JsonWebHttpBehaviour.cs&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;
An error dialog that&amp;#39;s based on user-control defined in previous articles (see &lt;strong&gt;/scripts/controls/error.js&lt;/strong&gt;,&lt;strong&gt; /scripts/controls/error.resources.js&lt;/strong&gt; and &lt;strong&gt;/scripts/templates/error.tmpl.html&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;
A client-side error handler that displays errors in user-friendly&amp;#39;s manner (see &lt;strong&gt;/scripts/api/api.js&lt;/strong&gt;,
method &lt;strong&gt;defaultErrorHandler()&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Of course this is only a draft solution, but it defines a direction for further customizations
in your web applications.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>javascript</category>
      <category>kendoui</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=b17502e5-9edf-43d2-9fab-7a5a3124ddf5</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b17502e5-9edf-43d2-9fab-7a5a3124ddf5.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,b17502e5-9edf-43d2-9fab-7a5a3124ddf5.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=b17502e5-9edf-43d2-9fab-7a5a3124ddf5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Kendo UI Docs contains an article "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;url=http%3a%2f%2fdocs.kendoui.com%2fhowto%2fload-templates-external-files">How
To: Load Templates from External Files</a>", where authors review two way of
dealing with Kendo UI templates.
</p>
        <p>
While using Kendo UI we have found our own answer to: <i>where will the Kendo UI templates
be defined and maintained?</i></p>
        <p style="float: right">
          <img alt="solution tree" src="content/binary/templates.png" style="width: 320px" />
        </p>
        <p>
In our .NET project we have decided to keep templates separately, and to store them
under the "templates" folder. Those templates are in fact include html,
head, and stylesheet links. This is to help us to present those tempates in the design
view. 
</p>
        <p>
In our scripts folder, we have defined a small text transformation template: "templates.tt",
which produces "templates.js" file. This template takes body contents of
each "*.tmpl.html" file from "templates" folder and builds string
of the form:
</p>
        <p style="padding-left: 1em">
          <code>document.write('&lt;script id="footer-template" type="text/x-kendo-template"&gt;...&lt;/script&gt;&lt;script
id="row-template" type="text/x-kendo-template"&gt;...&lt;/script&gt;');</code>
        </p>
        <p>
In our page that uses templates, we include "templates.js":
</p>
        <p style="padding-left: 1em">
          <code> &lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;script src="scripts/templates.js"&gt;&lt;/script&gt; 
<br />
...</code>
        </p>
        <p>
Thus, we have:
</p>
        <ul>
          <li>
clean separation of templates and page content;</li>
          <li>
automatically generated templates include file.</li>
        </ul>
        <p>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fWebTemplates.zip">WebTemplates.zip</a> contains
a web project demonstrating our technique. "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2ftemplates.tt.txt">templates.tt</a>"
is text template transformation used in the project.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5" />
      </body>
      <title>How To: Load KendoUI Templates from External Files</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b17502e5-9edf-43d2-9fab-7a5a3124ddf5.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/01/06/HowToLoadKendoUITemplatesFromExternalFiles.aspx</link>
      <pubDate>Sun, 06 Jan 2013 19:43:19 GMT</pubDate>
      <description>&lt;p&gt;
Kendo UI Docs contains an article &amp;quot;&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;amp;url=http%3a%2f%2fdocs.kendoui.com%2fhowto%2fload-templates-external-files"&gt;How
To: Load Templates from External Files&lt;/a&gt;&amp;quot;, where authors review two way of
dealing with Kendo UI templates.
&lt;/p&gt;
&lt;p&gt;
While using Kendo UI we have found our own answer to: &lt;i&gt;where will the Kendo UI templates
be defined and maintained?&lt;/i&gt;
&lt;/p&gt;
&lt;p style="float: right"&gt;
&lt;img alt="solution tree" src="content/binary/templates.png" style="width: 320px" /&gt;
&lt;/p&gt;
&lt;p&gt;
In our .NET project we have decided to keep templates separately, and to store them
under the &amp;quot;templates&amp;quot; folder. Those templates are in fact include html,
head, and stylesheet links. This is to help us to present those tempates in the design
view. 
&lt;/p&gt;
&lt;p&gt;
In our scripts folder, we have defined a small text transformation template: &amp;quot;templates.tt&amp;quot;,
which produces &amp;quot;templates.js&amp;quot; file. This template takes body contents of
each &amp;quot;*.tmpl.html&amp;quot; file from &amp;quot;templates&amp;quot; folder and builds string
of the form:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;document.write('&amp;lt;script id="footer-template" type="text/x-kendo-template"&amp;gt;...&amp;lt;/script&amp;gt;&amp;lt;script
id="row-template" type="text/x-kendo-template"&amp;gt;...&amp;lt;/script&amp;gt;');&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
In our page that uses templates, we include &amp;quot;templates.js&amp;quot;:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; &amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;script src=&amp;quot;scripts/templates.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt; 
&lt;br /&gt;
...&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Thus, we have:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
clean separation of templates and page content;&lt;/li&gt;
&lt;li&gt;
automatically generated templates include file.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fWebTemplates.zip"&gt;WebTemplates.zip&lt;/a&gt; contains
a web project demonstrating our technique. &amp;quot;&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2ftemplates.tt.txt"&gt;templates.tt&lt;/a&gt;&amp;quot;
is text template transformation used in the project.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,b17502e5-9edf-43d2-9fab-7a5a3124ddf5.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>javascript</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=98b58257-9069-4d13-9d10-a7061e14e834</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,98b58257-9069-4d13-9d10-a7061e14e834.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,98b58257-9069-4d13-9d10-a7061e14e834.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=98b58257-9069-4d13-9d10-a7061e14e834</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you deal with web applications you probably have already dealt with export data
to Excel. There are several options to prepare data for Excel:
</p>
        <ul>
          <li>
generate CSV;</li>
          <li>
generate HTML that excel understands;</li>
          <li>
generate XML in Spreadsheet 2003 format;</li>
          <li>
generate data using Open XML SDK or some other 3rd party libraries;</li>
          <li>
generate data in XLSX format, according to Open XML specification.</li>
        </ul>
        <p>
You may find a good article with pros and cons of each solution <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=98b58257-9069-4d13-9d10-a7061e14e834&amp;url=http%3a%2f%2fblogs.msdn.com%2fb%2ferikaehrli%2farchive%2f2009%2f01%2f30%2fhow-to-export-data-to-excel-from-an-asp-net-application-avoid-the-file-format-differ-prompt.aspx" target="_blank">here</a>.
We, in our turn, would like to share our experience in this field. Let's start from
requirements:
</p>
        <ul>
          <li>
Often we have to export huge data-sets.</li>
          <li>
We should be able to format, parametrize and to apply different styles to the exported
data.</li>
          <li>
There are cases when exported data may contain more than one table per sheet or even
more than one sheet.</li>
          <li>
Some exported data have to be illustrated with charts.</li>
        </ul>
        <p>
All these requirements led us to a solution based on XSLT processing of streamed data.
The advantage of this solution is that the result is immediately forwarded to a client
as fast as XSLT starts to generate output. Such approach is much productive than generating
of XLSX using of Open XML SDK or any other third party library, since it avoids keeping
a huge data-sets in memory on the server side.
</p>
        <p style="direction: ltr">
Another advantage - is simple maintenance, as we achieve clear separation of data
and presentation layers. On each request to change formatting or apply another style
to a cell you just have to modify xslt file(s) that generate variable parts of XLSX.
</p>
        <p>
As result, our clients get XLSX files according with Open XML specifications. The
details of implementations of our solution see in our next posts.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=98b58257-9069-4d13-9d10-a7061e14e834" />
      </body>
      <title>Export data to Excel</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,98b58257-9069-4d13-9d10-a7061e14e834.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/10/29/ExportDataToExcel.aspx</link>
      <pubDate>Mon, 29 Oct 2012 15:34:38 GMT</pubDate>
      <description>&lt;p&gt;
If you deal with web applications you probably have already dealt with export data
to Excel. There are several options to prepare data for Excel:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
generate CSV;&lt;/li&gt;
&lt;li&gt;
generate HTML that excel understands;&lt;/li&gt;
&lt;li&gt;
generate XML in Spreadsheet 2003 format;&lt;/li&gt;
&lt;li&gt;
generate data using Open XML SDK or some other 3rd party libraries;&lt;/li&gt;
&lt;li&gt;
generate data in XLSX format, according to Open XML specification.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
You may find a good article with pros and cons of each solution &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=98b58257-9069-4d13-9d10-a7061e14e834&amp;amp;url=http%3a%2f%2fblogs.msdn.com%2fb%2ferikaehrli%2farchive%2f2009%2f01%2f30%2fhow-to-export-data-to-excel-from-an-asp-net-application-avoid-the-file-format-differ-prompt.aspx" target="_blank"&gt;here&lt;/a&gt;.
We, in our turn, would like to share our experience in this field. Let's start from
requirements:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Often we have to export huge data-sets.&lt;/li&gt;
&lt;li&gt;
We should be able to format, parametrize and to apply different styles to the exported
data.&lt;/li&gt;
&lt;li&gt;
There are cases when exported data may contain more than one table per sheet or even
more than one sheet.&lt;/li&gt;
&lt;li&gt;
Some exported data have to be illustrated with charts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
All these requirements led us to a solution based on XSLT processing of streamed data.
The advantage of this solution is that the result is immediately forwarded to a client
as fast as XSLT starts to generate output. Such approach is much productive than generating
of XLSX using of Open XML SDK or any other third party library, since it avoids keeping
a huge data-sets in memory on the server side.
&lt;/p&gt;
&lt;p style="direction: ltr"&gt;
Another advantage - is simple maintenance, as we achieve clear separation of data
and presentation layers. On each request to change formatting or apply another style
to a cell you just have to modify xslt file(s) that generate variable parts of XLSX.
&lt;/p&gt;
&lt;p&gt;
As result, our clients get XLSX files according with Open XML specifications. The
details of implementations of our solution see in our next posts.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=98b58257-9069-4d13-9d10-a7061e14e834" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,98b58257-9069-4d13-9d10-a7061e14e834.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=cad54317-1876-4b98-a8d2-7e44e5dda1f7</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,cad54317-1876-4b98-a8d2-7e44e5dda1f7.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,cad54317-1876-4b98-a8d2-7e44e5dda1f7.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=cad54317-1876-4b98-a8d2-7e44e5dda1f7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Earlier we have shown <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2012%2f07%2f22%2fStreamingEntityData.aspx"> how
to build streaming xml reader from business data</a> and have reminded about <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2012%2f07%2f26%2fStreamingXsltTransformationWithForwardXPathNavigator.aspx">ForwardXPathNavigator
which helps to create a streaming xslt transformation</a>. Now we want to show how
to stream content produced with xslt out of WCF service.
</p>
        <p>
To achieve streaming in WCF one needs: 
</p>
        <p>
1. To configure service to use streaming. Description on how to do this can be found
in the internet. See web.config of the sample <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fStreaming.zip"> Streaming.zip</a> for
the details.
</p>
        <p>
2. Create a service with a method returning <code>Stream</code>:
</p>
        <p>
          <code>[ServiceContract(Namespace = "http://www.nesterovsky-bros.com")]<br />
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]<br />
public class Service<br />
{<br />
[OperationContract]<br />
[WebGet(RequestFormat = WebMessageFormat.Json)]<br />
public Stream GetPeopleHtml(int count, int seed)<br />
{<br />
...<br />
}<br />
}</code>
        </p>
        <p>
2. Return a <code>Stream</code> from xsl transformation. 
</p>
        <p>
Unfortunately (we mentioned it already), <code>XslCompiledTransform</code> generates
its output into <code>XmlWriter</code> (or into output <code>Stream</code>) rather
than exposes result as <code>XmlReader</code>, while WCF gets input stream and passes
it to a client. 
</p>
        <p>
We could generate xslt output into a file or a memory <code>Stream</code> and then
return that content as input <code>Stream</code>, but this will defeat a goal of streaming,
as client would have started to get data no earlier that the xslt completed its work.
What we need instead is a pipe that form xslt output <code>Stream</code> to an input <code>Stream</code> returned
from WCF.
</p>
        <p>
.NET implements pipe streams, so our task is trivial. We have defined a utility method
that creates an input <code>Stream</code> from a generator populating an output <code>Stream</code>:
</p>
        <p>
          <code> public static Stream GetPipedStream(Action&lt;Stream&gt; generator)<br />
{<br />
var output = new AnonymousPipeServerStream();<br />
var input = new AnonymousPipeClientStream(<br />
output.GetClientHandleAsString());<br /><br />
Task.Factory.StartNew(<br />
() =&gt;<br />
{<br />
using(output)<br />
{<br />
generator(output);<br />
output.WaitForPipeDrain();<br />
}<br />
},<br />
TaskCreationOptions.LongRunning);<br /><br />
return input;<br />
} </code>
        </p>
        <p>
We wrapped xsl transformation as such a generator:
</p>
        <p>
          <code>[OperationContract]<br />
[WebGet(RequestFormat = WebMessageFormat.Json)]<br />
public Stream GetPeopleHtml(int count, int seed)<br />
{<br />
var context = WebOperationContext.Current;<br /><br />
context.OutgoingResponse.ContentType = "text/html";<br />
context.OutgoingResponse.Headers["Content-Disposition"] = 
<br />
"attachment;filename=reports.html";<br /><br />
var cache = HttpRuntime.Cache;<br />
var path = HttpContext.Current.Server.MapPath("~/People.xslt");<br />
var transform = cache[path] as XslCompiledTransform;<br /><br />
if (transform == null)<br />
{<br />
transform = new XslCompiledTransform();<br />
transform.Load(path);<br />
cache.Insert(path, transform, new CacheDependency(path));<br />
}<br /><br />
return Extensions.<strong>GetPipedStream</strong>(<br />
output =&gt;<br />
{<br />
// We have a streamed business data.<br />
var people = Data.CreateRandomData(count, seed, 0, count);<br /><br />
// We want to see it as streamed xml data.<br />
using(var stream =<br />
people.<strong>ToXmlStream</strong>("people", "http://www.nesterovsky-bros.com"))<br />
using(var reader = XmlReader.Create(stream))<br />
{<br />
// XPath forward navigator is used as an input source.<br />
transform.Transform(<br />
new <strong>ForwardXPathNavigator</strong>(reader),<br />
new XsltArgumentList(),<br />
output);<br />
}<br />
});<br />
}</code>
        </p>
        <p>
This way we have build a code that streams data directly from business data to a client
in a form of report. A set of utility functions and classes helped us to overcome
.NET's limitations and to build simple code that one can easily support.
</p>
        <p>
The sources can be found at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fStreaming.zip"> Streaming.zip</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7" />
      </body>
      <title>Stream xslt transformation through WCF</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,cad54317-1876-4b98-a8d2-7e44e5dda1f7.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/08/03/StreamXsltTransformationThroughWCF.aspx</link>
      <pubDate>Fri, 03 Aug 2012 22:32:49 GMT</pubDate>
      <description>  &lt;p&gt;
Earlier we have shown &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2012%2f07%2f22%2fStreamingEntityData.aspx"&gt; how
to build streaming xml reader from business data&lt;/a&gt; and have reminded about &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2012%2f07%2f26%2fStreamingXsltTransformationWithForwardXPathNavigator.aspx"&gt;ForwardXPathNavigator
which helps to create a streaming xslt transformation&lt;/a&gt;. Now we want to show how
to stream content produced with xslt out of WCF service.
&lt;/p&gt;
&lt;p&gt;
To achieve streaming in WCF one needs: 
&lt;/p&gt;
&lt;p&gt;
1. To configure service to use streaming. Description on how to do this can be found
in the internet. See web.config of the sample &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fStreaming.zip"&gt; Streaming.zip&lt;/a&gt; for
the details.
&lt;/p&gt;
&lt;p&gt;
2. Create a service with a method returning &lt;code&gt;Stream&lt;/code&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;[ServiceContract(Namespace = "http://www.nesterovsky-bros.com")]&lt;br /&gt;
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]&lt;br /&gt;
public class Service&lt;br /&gt;
{&lt;br /&gt;
[OperationContract]&lt;br /&gt;
[WebGet(RequestFormat = WebMessageFormat.Json)]&lt;br /&gt;
public Stream GetPeopleHtml(int count, int seed)&lt;br /&gt;
{&lt;br /&gt;
...&lt;br /&gt;
}&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
2. Return a &lt;code&gt;Stream&lt;/code&gt; from xsl transformation. 
&lt;/p&gt;
&lt;p&gt;
Unfortunately (we mentioned it already), &lt;code&gt;XslCompiledTransform&lt;/code&gt; generates
its output into &lt;code&gt;XmlWriter&lt;/code&gt; (or into output &lt;code&gt;Stream&lt;/code&gt;) rather
than exposes result as &lt;code&gt;XmlReader&lt;/code&gt;, while WCF gets input stream and passes
it to a client. 
&lt;/p&gt;
&lt;p&gt;
We could generate xslt output into a file or a memory &lt;code&gt;Stream&lt;/code&gt; and then
return that content as input &lt;code&gt;Stream&lt;/code&gt;, but this will defeat a goal of streaming,
as client would have started to get data no earlier that the xslt completed its work.
What we need instead is a pipe that form xslt output &lt;code&gt;Stream&lt;/code&gt; to an input &lt;code&gt;Stream&lt;/code&gt; returned
from WCF.
&lt;/p&gt;
&lt;p&gt;
.NET implements pipe streams, so our task is trivial. We have defined a utility method
that creates an input &lt;code&gt;Stream&lt;/code&gt; from a generator populating an output &lt;code&gt;Stream&lt;/code&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt; public static Stream GetPipedStream(Action&amp;lt;Stream&amp;gt; generator)&lt;br /&gt;
{&lt;br /&gt;
var output = new AnonymousPipeServerStream();&lt;br /&gt;
var input = new AnonymousPipeClientStream(&lt;br /&gt;
output.GetClientHandleAsString());&lt;br /&gt;
&lt;br /&gt;
Task.Factory.StartNew(&lt;br /&gt;
() =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
using(output)&lt;br /&gt;
{&lt;br /&gt;
generator(output);&lt;br /&gt;
output.WaitForPipeDrain();&lt;br /&gt;
}&lt;br /&gt;
},&lt;br /&gt;
TaskCreationOptions.LongRunning);&lt;br /&gt;
&lt;br /&gt;
return input;&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
We wrapped xsl transformation as such a generator:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;[OperationContract]&lt;br /&gt;
[WebGet(RequestFormat = WebMessageFormat.Json)]&lt;br /&gt;
public Stream GetPeopleHtml(int count, int seed)&lt;br /&gt;
{&lt;br /&gt;
var context = WebOperationContext.Current;&lt;br /&gt;
&lt;br /&gt;
context.OutgoingResponse.ContentType = "text/html";&lt;br /&gt;
context.OutgoingResponse.Headers["Content-Disposition"] = 
&lt;br /&gt;
"attachment;filename=reports.html";&lt;br /&gt;
&lt;br /&gt;
var cache = HttpRuntime.Cache;&lt;br /&gt;
var path = HttpContext.Current.Server.MapPath("~/People.xslt");&lt;br /&gt;
var transform = cache[path] as XslCompiledTransform;&lt;br /&gt;
&lt;br /&gt;
if (transform == null)&lt;br /&gt;
{&lt;br /&gt;
transform = new XslCompiledTransform();&lt;br /&gt;
transform.Load(path);&lt;br /&gt;
cache.Insert(path, transform, new CacheDependency(path));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return Extensions.&lt;strong&gt;GetPipedStream&lt;/strong&gt;(&lt;br /&gt;
output =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
// We have a streamed business data.&lt;br /&gt;
var people = Data.CreateRandomData(count, seed, 0, count);&lt;br /&gt;
&lt;br /&gt;
// We want to see it as streamed xml data.&lt;br /&gt;
using(var stream =&lt;br /&gt;
people.&lt;strong&gt;ToXmlStream&lt;/strong&gt;("people", "http://www.nesterovsky-bros.com"))&lt;br /&gt;
using(var reader = XmlReader.Create(stream))&lt;br /&gt;
{&lt;br /&gt;
// XPath forward navigator is used as an input source.&lt;br /&gt;
transform.Transform(&lt;br /&gt;
new &lt;strong&gt;ForwardXPathNavigator&lt;/strong&gt;(reader),&lt;br /&gt;
new XsltArgumentList(),&lt;br /&gt;
output);&lt;br /&gt;
}&lt;br /&gt;
});&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
This way we have build a code that streams data directly from business data to a client
in a form of report. A set of utility functions and classes helped us to overcome
.NET&amp;#39;s limitations and to build simple code that one can easily support.
&lt;/p&gt;
&lt;p&gt;
The sources can be found at &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fStreaming.zip"&gt; Streaming.zip&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,cad54317-1876-4b98-a8d2-7e44e5dda1f7.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=8383cfc7-10ac-4f2a-a249-4cc37ddbac70</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8383cfc7-10ac-4f2a-a249-4cc37ddbac70.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,8383cfc7-10ac-4f2a-a249-4cc37ddbac70.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=8383cfc7-10ac-4f2a-a249-4cc37ddbac70</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
For a long time we were developing web applications with ASP.NET and JSF. At present
we prefer rich clients and a server with page templates and RESTful web services.
</p>
        <p>
This transition brings technical questions. Consider this one.
</p>
        <p>
Browsers allow to store session state entirely on the client, so should we maintain
a session on the server?
</p>
        <p>
Since the server is just a set of web services, so we may supply all required arguments
on each call. 
</p>
        <p>
At first glance we can assume that no session is required on the server. However,
looking further we see that we should deal with data validation (security) on the
server. 
</p>
        <p>
Think about a classic ASP.NET application, where a user can select a value from a
dropdown. Either ASP.NET itself or your program (against a list from a session) verifies
that the value received is valid for the user. That list of values and might be other
parameters constitute a user profile, which we stored in session. The user profile
played important role (often indirectly) in the validation of input data.
</p>
        <p>
When the server is just a set of web services then we have to validate all parameters
manually. There are two sources that we can rely to: (a) <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fsystem.web.services.webservice.session.aspx"> a
session</a>, (b) <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fsystem.web.services.webservice.user.aspx"> a
user principal</a>.
</p>
        <p>
The case (a) is very similar to classic ASP.NET application except that with <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fydy4x04a.aspx">EnableEventValidation="true"</a> runtime
did it for us most of the time.<br />
The case (b) requires reconstruction of the user profile for a user principal and
then we proceed with validation of parameters. 
</p>
        <p>
We may cache user profile in session, in which case we reduce (b) to (a); on the other
hand we may cache user profile in <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fsystem.web.caching.cache.aspx"> Cache</a>,
which is also similar to (a) but which might be lighter than (at least not heavier
than) the solution with the session.
</p>
        <p>
What we see is that the client session does not free us from server session (or its
alternative).
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70" />
      </body>
      <title>Shifting to client side web applications</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8383cfc7-10ac-4f2a-a249-4cc37ddbac70.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/03/08/ShiftingToClientSideWebApplications.aspx</link>
      <pubDate>Thu, 08 Mar 2012 21:56:19 GMT</pubDate>
      <description>  &lt;p&gt;
For a long time we were developing web applications with ASP.NET and JSF. At present
we prefer rich clients and a server with page templates and RESTful web services.
&lt;/p&gt;
&lt;p&gt;
This transition brings technical questions. Consider this one.
&lt;/p&gt;
&lt;p&gt;
Browsers allow to store session state entirely on the client, so should we maintain
a session on the server?
&lt;/p&gt;
&lt;p&gt;
Since the server is just a set of web services, so we may supply all required arguments
on each call. 
&lt;/p&gt;
&lt;p&gt;
At first glance we can assume that no session is required on the server. However,
looking further we see that we should deal with data validation (security) on the
server. 
&lt;/p&gt;
&lt;p&gt;
Think about a classic ASP.NET application, where a user can select a value from a
dropdown. Either ASP.NET itself or your program (against a list from a session) verifies
that the value received is valid for the user. That list of values and might be other
parameters constitute a user profile, which we stored in session. The user profile
played important role (often indirectly) in the validation of input data.
&lt;/p&gt;
&lt;p&gt;
When the server is just a set of web services then we have to validate all parameters
manually. There are two sources that we can rely to: (a) &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fsystem.web.services.webservice.session.aspx"&gt; a
session&lt;/a&gt;, (b) &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fsystem.web.services.webservice.user.aspx"&gt; a
user principal&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The case (a) is very similar to classic ASP.NET application except that with &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fydy4x04a.aspx"&gt;EnableEventValidation="true"&lt;/a&gt; runtime
did it for us most of the time.&lt;br /&gt;
The case (b) requires reconstruction of the user profile for a user principal and
then we proceed with validation of parameters. 
&lt;/p&gt;
&lt;p&gt;
We may cache user profile in session, in which case we reduce (b) to (a); on the other
hand we may cache user profile in &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fsystem.web.caching.cache.aspx"&gt; Cache&lt;/a&gt;,
which is also similar to (a) but which might be lighter than (at least not heavier
than) the solution with the session.
&lt;/p&gt;
&lt;p&gt;
What we see is that the client session does not free us from server session (or its
alternative).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8383cfc7-10ac-4f2a-a249-4cc37ddbac70" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,8383cfc7-10ac-4f2a-a249-4cc37ddbac70.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>Java</category>
      <category>JSF and Facelets</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ad1c5ce2-4806-4de7-8c58-6af54cb9df06</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ad1c5ce2-4806-4de7-8c58-6af54cb9df06</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It has happened so, that we have never worked with jQuery, however were aware of it.
</p>
        <p>
In early 2000 we have developed a web application that contained rich javascript APIs,
including UI components. Later, we were actively practicing in ASP.NET, and later
in JSF.
</p>
        <p>
At present, looking at jQuery more closely we regret that we have failed to start
using it earlier.
</p>
        <p>
Separation of business logic and presentation is remarkable when one uses JSON web
services. In fact server part can be seen as a set of web services representing a
business logic and a set of resources: html, styles, scripts, others. Nor ASP.NET
or JSF approach such a consistent separation.
</p>
        <p>
The only trouble, in our opinion, is that jQuery has no standard data binding: a way
to bind JSON data to (and from) html controls. The technique that will probably be
standardized is called <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06&amp;url=https%3a%2f%2fgithub.com%2fBorisMoore%2fjsviews">jQuery
Templates or JsViews </a> .
</p>
        <p>
Unfortunatelly after reading about this <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06&amp;url=http%3a%2f%2fwiki.jqueryui.com%2fw%2fpage%2f37898666%2fTemplate">binding
API</a>, and being in love with Xslt and XQuery we just want to cry. We don't know
what would be the best solution for the task, but what we see looks uncomfortable
to us.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06" />
      </body>
      <title>jQuery</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/10/28/jQuery.aspx</link>
      <pubDate>Fri, 28 Oct 2011 22:59:23 GMT</pubDate>
      <description>&lt;p&gt;
It has happened so, that we have never worked with jQuery, however were aware of it.
&lt;/p&gt;
&lt;p&gt;
In early 2000 we have developed a web application that contained rich javascript APIs,
including UI components. Later, we were actively practicing in ASP.NET, and later
in JSF.
&lt;/p&gt;
&lt;p&gt;
At present, looking at jQuery more closely we regret that we have failed to start
using it earlier.
&lt;/p&gt;
&lt;p&gt;
Separation of business logic and presentation is remarkable when one uses JSON web
services. In fact server part can be seen as a set of web services representing a
business logic and a set of resources: html, styles, scripts, others. Nor ASP.NET
or JSF approach such a consistent separation.
&lt;/p&gt;
&lt;p&gt;
The only trouble, in our opinion, is that jQuery has no standard data binding: a way
to bind JSON data to (and from) html controls. The technique that will probably be
standardized is called &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06&amp;amp;url=https%3a%2f%2fgithub.com%2fBorisMoore%2fjsviews"&gt;jQuery
Templates or JsViews &lt;/a&gt; .
&lt;/p&gt;
&lt;p&gt;
Unfortunatelly after reading about this &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06&amp;amp;url=http%3a%2f%2fwiki.jqueryui.com%2fw%2fpage%2f37898666%2fTemplate"&gt;binding
API&lt;/a&gt;, and being in love with Xslt and XQuery we just want to cry. We don't know
what would be the best solution for the task, but what we see looks uncomfortable
to us.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</comments>
      <category>ASP.NET</category>
      <category>JSF and Facelets</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=abbaf525-f50f-48f8-b54a-a01e1a9b6d95</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,abbaf525-f50f-48f8-b54a-a01e1a9b6d95.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,abbaf525-f50f-48f8-b54a-a01e1a9b6d95.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=abbaf525-f50f-48f8-b54a-a01e1a9b6d95</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <code>AjaxControlToolkit</code> has methods to access <code>ViewState</code>:
</p>
        <p style="padding-left: 1em">
          <code> protected V GetPropertyValue&lt;V&gt;(string propertyName, V nullValue)<br />
{<br />
  if (this.ViewState[propertyName] == null)<br />
  {<br />
    return nullValue;<br />
  }<br /><br />
  return (V) this.ViewState[propertyName];<br />
}<br /><br />
protected void SetPropertyValue&lt;V&gt;(string propertyName, V value)<br />
{<br />
  this.ViewState[propertyName] = value;<br />
}<br /><br />
...<br /><br />
public bool EnabledOnClient<br />
{<br />
  get { return base.GetPropertyValue<bool>
("EnabledOnClient", true); } 
<br />
  set { base.SetPropertyValue<bool>
("EnabledOnClient", value); }<br />
}
</bool></bool></code>
        </p>
        <p>
We find that code unnecessary complex and nonoptimal. Our code to access <code>ViewState</code> looks
like this:
</p>
        <p style="padding-left: 1em">
          <code>public bool EnabledOnClient<br />
{<br />
  get { return ViewState["EnabledOnClient"] as bool? ?? true); } 
<br />
  set { ViewState["EnabledOnClient"] = value; }<br />
}</code>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=abbaf525-f50f-48f8-b54a-a01e1a9b6d95" />
      </body>
      <title>View state access</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,abbaf525-f50f-48f8-b54a-a01e1a9b6d95.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/08/28/ViewStateAccess.aspx</link>
      <pubDate>Sun, 28 Aug 2011 19:35:13 GMT</pubDate>
      <description>&lt;p&gt;
&lt;code&gt;AjaxControlToolkit&lt;/code&gt; has methods to access &lt;code&gt;ViewState&lt;/code&gt;:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; protected V GetPropertyValue&amp;lt;V&amp;gt;(string propertyName, V nullValue)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; if (this.ViewState[propertyName] == null)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return nullValue;&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; return (V) this.ViewState[propertyName];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
protected void SetPropertyValue&amp;lt;V&amp;gt;(string propertyName, V value)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; this.ViewState[propertyName] = value;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
public bool EnabledOnClient&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; get { return base.GetPropertyValue&lt;bool&gt;
(&amp;quot;EnabledOnClient&amp;quot;, true); } 
&lt;br /&gt;
&amp;nbsp; set { base.SetPropertyValue&lt;bool&gt;
(&amp;quot;EnabledOnClient&amp;quot;, value); }&lt;br /&gt;
}
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
We find that code unnecessary complex and nonoptimal. Our code to access &lt;code&gt;ViewState&lt;/code&gt; looks
like this:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;public bool EnabledOnClient&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; get { return ViewState[&amp;quot;EnabledOnClient&amp;quot;] as bool? ?? true); } 
&lt;br /&gt;
&amp;nbsp; set { ViewState[&amp;quot;EnabledOnClient&amp;quot;] = value; }&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=abbaf525-f50f-48f8-b54a-a01e1a9b6d95" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,abbaf525-f50f-48f8-b54a-a01e1a9b6d95.aspx</comments>
      <category>ASP.NET</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=14fc97f7-2481-4a91-abfc-b2d2ca4ed136</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,14fc97f7-2481-4a91-abfc-b2d2ca4ed136.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,14fc97f7-2481-4a91-abfc-b2d2ca4ed136.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=14fc97f7-2481-4a91-abfc-b2d2ca4ed136</wfw:commentRss>
      <slash:comments>8</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Already for a couple of days we're trying to create a UserControl containing a <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=14fc97f7-2481-4a91-abfc-b2d2ca4ed136&amp;url=http%3a%2f%2fwww.asp.net%2fajax%2fajaxcontroltoolkit%2fsamples%2ftabs%2ftabs.aspx"> TabContainer</a>.
To achieve the goal we have created a page with a ToolkitScriptManager and a user
control itself.
</p>
        <p>
Page:
</p>
        <p style="padding-left: 1em">
          <code>&lt;form runat="server"&gt;<br />
&lt;ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/&gt;<br />
&lt;uc1:WebUserControl1 ID="WebUserControl11" runat="server" /&gt;<br />
&lt;/form&gt;</code>
        </p>
        <p>
User control:
</p>
        <p style="padding-left: 1em">
          <code>&lt;%@ Control Language="C#" %&gt; 
<br />
&lt;%@ Register<br />
Assembly="AjaxControlToolkit"<br />
Namespace="AjaxControlToolkit"<br />
TagPrefix="ajax" %&gt;<br /><br />
&lt;ajax:TabContainer ID="Tab" runat="server" Width="100%"&gt;<br />
&lt;ajax:TabPanel runat="server" HeaderText="Tab1" ID="Tab1"&gt;<br />
&lt;ContentTemplate&gt;Panel 1&lt;/ContentTemplate&gt;<br />
&lt;/ajax:TabPanel&gt;<br />
&lt;/ajax:TabContainer&gt;</code>
        </p>
        <p>
What could be more simple?
</p>
        <p>
But no, there is a problem. At run-time control works perfectly, but at the designer
it shows an error instead of a normal design view:
</p>
        <p style="padding-left: 1em;">
          <code>
            <span style="color: red">Error Rendering Control</span> - TabContainer1<br />
An unhandled exception has occurred.<br />
Could not find any resources appropriate for the specified culture or the neutral
culture. Make sure "AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly
embedded or linked into assembly "AjaxControlToolkit" at compile time, or that all
the satellite assemblies required are loadable and fully signed.</code>
        </p>
        <p>
That's a stupid error, which says nothing about the real problem reason. We had
to attach a debugger to a Visual Studio just to realize what the problem is.
</p>
        <p>
So, the error occurs at the following code of AjaxControlToolkit.ScriptControlBase:
</p>
        <p>
          <code>private void EnsureScriptManager()<br />
{<br />
if (this._scriptManager == null)<br />
{<br />
this._scriptManager = ScriptManager.GetCurrent(this.Page);<br /><br />
if (this._scriptManager == null)<br />
{<br />
throw new HttpException(Resources.E_NoScriptManager);<br />
}<br />
}<br />
} </code>
        </p>
        <p>
Originally, the problem is due to the fact that ScriptManager is not found, and code
wants to report an <code>HttpException</code>, but fun is that we recieve a different
exception, which is releted to a missing resouce text for a message <code>Resources.E_NoScriptManager</code>.
It turns out that <code>E_NoScriptManager</code> text is found neither in primary
no in resource assemblies.
</p>
        <p>
As for original problem, it's hard to say about reason of why ScriptManager is
not available at design time. We, however, observed that a ScriptManager registers
itself for a <code>ScriptManager.GetCurrent()</code> method at run-time only:
</p>
        <p style="padding-left: 1em">
          <code>protected internal override void OnInit(EventArgs e)<br />
{<br />
...<br />
if (!base.DesignMode)<br />
{<br />
... 
<br />
iPage.Items[typeof(ScriptManager)] = this;<br />
...<br />
}<br />
} </code>
        </p>
        <p>
So, it's not clear what they (toolkit's developers) expected to get at design
time.
</p>
        <p>
These observations leave uneasiness regarding the quality of the library.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=14fc97f7-2481-4a91-abfc-b2d2ca4ed136" />
      </body>
      <title>AjaxControlToolkit nuisance</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,14fc97f7-2481-4a91-abfc-b2d2ca4ed136.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/05/03/AjaxControlToolkitNuisance.aspx</link>
      <pubDate>Tue, 03 May 2011 19:45:51 GMT</pubDate>
      <description>  &lt;p&gt;
Already for a couple of days we&amp;#39;re trying to create a UserControl containing a &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=14fc97f7-2481-4a91-abfc-b2d2ca4ed136&amp;amp;url=http%3a%2f%2fwww.asp.net%2fajax%2fajaxcontroltoolkit%2fsamples%2ftabs%2ftabs.aspx"&gt; TabContainer&lt;/a&gt;.
To achieve the goal we have created a page with a ToolkitScriptManager and a user
control itself.
&lt;/p&gt;
&lt;p&gt;
Page:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;form runat="server"&amp;gt;&lt;br /&gt;
&amp;lt;ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/&amp;gt;&lt;br /&gt;
&amp;lt;uc1:WebUserControl1 ID="WebUserControl11" runat="server" /&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
User control:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;%@ Control Language="C#" %&amp;gt; 
&lt;br /&gt;
&amp;lt;%@ Register&lt;br /&gt;
Assembly="AjaxControlToolkit"&lt;br /&gt;
Namespace="AjaxControlToolkit"&lt;br /&gt;
TagPrefix="ajax" %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ajax:TabContainer ID="Tab" runat="server" Width="100%"&amp;gt;&lt;br /&gt;
&amp;lt;ajax:TabPanel runat="server" HeaderText="Tab1" ID="Tab1"&amp;gt;&lt;br /&gt;
&amp;lt;ContentTemplate&amp;gt;Panel 1&amp;lt;/ContentTemplate&amp;gt;&lt;br /&gt;
&amp;lt;/ajax:TabPanel&amp;gt;&lt;br /&gt;
&amp;lt;/ajax:TabContainer&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
What could be more simple?
&lt;/p&gt;
&lt;p&gt;
But no, there is a problem. At run-time control works perfectly, but at the designer
it shows an error instead of a normal design view:
&lt;/p&gt;
&lt;p style="padding-left: 1em;"&gt;
&lt;code&gt; &lt;span style="color: red"&gt;Error Rendering Control&lt;/span&gt; - TabContainer1&lt;br /&gt;
An unhandled exception has occurred.&lt;br /&gt;
Could not find any resources appropriate for the specified culture or the neutral
culture. Make sure "AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly
embedded or linked into assembly "AjaxControlToolkit" at compile time, or that all
the satellite assemblies required are loadable and fully signed.&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
That&amp;#39;s a stupid error, which says nothing about the real problem reason. We had
to attach a debugger to a Visual Studio just to realize what the problem is.
&lt;/p&gt;
&lt;p&gt;
So, the error occurs at the following code of AjaxControlToolkit.ScriptControlBase:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;private void EnsureScriptManager()&lt;br /&gt;
{&lt;br /&gt;
if (this._scriptManager == null)&lt;br /&gt;
{&lt;br /&gt;
this._scriptManager = ScriptManager.GetCurrent(this.Page);&lt;br /&gt;
&lt;br /&gt;
if (this._scriptManager == null)&lt;br /&gt;
{&lt;br /&gt;
throw new HttpException(Resources.E_NoScriptManager);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Originally, the problem is due to the fact that ScriptManager is not found, and code
wants to report an &lt;code&gt;HttpException&lt;/code&gt;, but fun is that we recieve a different
exception, which is releted to a missing resouce text for a message &lt;code&gt;Resources.E_NoScriptManager&lt;/code&gt;.
It turns out that &lt;code&gt;E_NoScriptManager&lt;/code&gt; text is found neither in primary
no in resource assemblies.
&lt;/p&gt;
&lt;p&gt;
As for original problem, it&amp;#39;s hard to say about reason of why ScriptManager is
not available at design time. We, however, observed that a ScriptManager registers
itself for a &lt;code&gt;ScriptManager.GetCurrent()&lt;/code&gt; method at run-time only:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;protected internal override void OnInit(EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
...&lt;br /&gt;
if (!base.DesignMode)&lt;br /&gt;
{&lt;br /&gt;
... 
&lt;br /&gt;
iPage.Items[typeof(ScriptManager)] = this;&lt;br /&gt;
...&lt;br /&gt;
}&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
So, it&amp;#39;s not clear what they (toolkit&amp;#39;s developers) expected to get at design
time.
&lt;/p&gt;
&lt;p&gt;
These observations leave uneasiness regarding the quality of the library.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=14fc97f7-2481-4a91-abfc-b2d2ca4ed136" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,14fc97f7-2481-4a91-abfc-b2d2ca4ed136.aspx</comments>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=fa4e996d-ca6f-48d8-bc14-de3caa954e8e</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,fa4e996d-ca6f-48d8-bc14-de3caa954e8e.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,fa4e996d-ca6f-48d8-bc14-de3caa954e8e.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=fa4e996d-ca6f-48d8-bc14-de3caa954e8e</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It does not matter that DataBindExtender looks not usual in the ASP.NET. It turns
to be so handy that built-in data binding is not considered to be an option.
</p>
        <p>
After a short try, you uderstand that people tried very hard and have invented many
controls and methods like ObjectDataSource, FormView, Eval(), and Bind() with outcome,
which is very specific and limited.
</p>
        <p>
In contrast DataBindExtender performs:
</p>
        <ul>
          <li>
Two or one way data binding of any business data property to any control property; 
</li>
          <li>
Converts value before it's passed to the control, or into the business data; 
</li>
          <li>
Validates the value. 
</li>
        </ul>
        <p>
See an example:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;asp:TextBox id=Field8 EnableViewState="false" runat="server"&gt;&lt;/asp:TextBox&gt;<br />
&lt;bphx:DataBindExtender runat='server'<br />
  EnableViewState='false'<br />
  TargetControlID='Field8'<br />
  ControlProperty='Text'<br />
  DataSource='&lt;%# Import.ClearingMemberFirm %&gt;'<br />
  DataMember='Id'<br />
  Converter='&lt;%# Converters.AsString("XXXXX", false) %&gt;'<br />
  Validator='&lt;%# (extender, value) =&gt; Functions.CheckID(value as string)
%&gt;'/&gt;</code>
        </p>
        <p>
Here, we beside a regualar two way data binding of a property <code>Import.ClearingMemberFirm.Id</code> to
a property <code>Field8.Text</code>, format (parse) <code>Converters.AsString("XXXXX",
false)</code>, and finally validate an input value with a lambda function <code>(extender,
value) =&gt; Functions.CheckID(value as string)</code>.
</p>
        <p>
DataBindExtender works also well in template controls like asp:Repeater, asp:GridView,
and so on. Having your business data available, you may reduce a size of the ViewState
with <code>EnableViewState='false'</code>. This way DataBindExtender approaches page
development to a pattern called MVC.
</p>
        <p>
Recently, we have found that it's also useful to have a way to run a javascript during
the page load (e.g. you want to attach some client side event, or register a component).
DataBindExtender provides this with OnClientInit property, which is a javascript to
run on a client, where <code><b>this</b></code> refers to a DOM element:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>... OnClientInit='$addHandler(<b>this</b>, "change", function() { handleEvent(event,
"Field8"); } );'/&gt;</code>
        </p>
        <p>
allows us to attach <code>onchange</code> javascript event to the <code>asp:TextBox</code>.
</p>
        <p>
So, meantime we're very satisfied with what we can achieve with DataBindExtender.
It's more than JSF allows, and much more stronger and neater to what ASP.NET has provided.
</p>
        <p>
The sources can be found at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=fa4e996d-ca6f-48d8-bc14-de3caa954e8e&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2fDataBindExtender.cs.txt">DataBindExtender.cs</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=fa4e996d-ca6f-48d8-bc14-de3caa954e8e" />
      </body>
      <title>ASP.NET two way databinding and OnClientInit in DataBindExtender</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,fa4e996d-ca6f-48d8-bc14-de3caa954e8e.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2010/07/11/ASPNETTwoWayDatabindingAndOnClientInitInDataBindExtender.aspx</link>
      <pubDate>Sun, 11 Jul 2010 07:07:03 GMT</pubDate>
      <description>&lt;p&gt;
It does not matter that DataBindExtender looks not usual in the ASP.NET. It turns
to be so handy that built-in data binding is not considered to be an option.
&lt;/p&gt;
&lt;p&gt;
After a short try, you uderstand that people tried very hard and have invented many
controls and methods like ObjectDataSource, FormView, Eval(), and Bind() with outcome,
which is very specific and limited.
&lt;/p&gt;
&lt;p&gt;
In contrast DataBindExtender performs:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Two or one way data binding of any business data property to any control property; 
&lt;li&gt;
Converts value before it's passed to the control, or into the business data; 
&lt;li&gt;
Validates the value. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
See an example:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;asp:TextBox id=Field8 EnableViewState="false" runat="server"&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br&gt;
&amp;lt;bphx:DataBindExtender runat='server'&lt;br&gt;
&amp;nbsp; EnableViewState='false'&lt;br&gt;
&amp;nbsp; TargetControlID='Field8'&lt;br&gt;
&amp;nbsp; ControlProperty='Text'&lt;br&gt;
&amp;nbsp; DataSource='&amp;lt;%# Import.ClearingMemberFirm %&amp;gt;'&lt;br&gt;
&amp;nbsp; DataMember='Id'&lt;br&gt;
&amp;nbsp; Converter='&amp;lt;%# Converters.AsString("XXXXX", false) %&amp;gt;'&lt;br&gt;
&amp;nbsp; Validator='&amp;lt;%# (extender, value) =&amp;gt; Functions.CheckID(value as string)
%&amp;gt;'/&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Here, we beside a regualar two way data binding of a property &lt;code&gt;Import.ClearingMemberFirm.Id&lt;/code&gt; to
a property &lt;code&gt;Field8.Text&lt;/code&gt;, format (parse) &lt;code&gt;Converters.AsString("XXXXX",
false)&lt;/code&gt;, and finally validate an input value with a lambda function &lt;code&gt;(extender,
value) =&amp;gt; Functions.CheckID(value as string)&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
DataBindExtender works also well in template controls like asp:Repeater, asp:GridView,
and so on. Having your business data available, you may reduce a size of the ViewState
with &lt;code&gt;EnableViewState='false'&lt;/code&gt;. This way DataBindExtender approaches page
development to a pattern called MVC.
&lt;/p&gt;
&lt;p&gt;
Recently, we have found that it's also useful to have a way to run a javascript during
the page load (e.g. you want to attach some client side event, or register a component).
DataBindExtender provides this with OnClientInit property, which is a javascript to
run on a client, where &lt;code&gt;&lt;b&gt;this&lt;/b&gt;&lt;/code&gt; refers to a DOM element:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;... OnClientInit='$addHandler(&lt;b&gt;this&lt;/b&gt;, "change", function() { handleEvent(event,
"Field8"); } );'/&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
allows us to attach &lt;code&gt;onchange&lt;/code&gt; javascript event to the &lt;code&gt;asp:TextBox&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
So, meantime we're very satisfied with what we can achieve with DataBindExtender.
It's more than JSF allows, and much more stronger and neater to what ASP.NET has provided.
&lt;/p&gt;
&lt;p&gt;
The sources can be found at &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=fa4e996d-ca6f-48d8-bc14-de3caa954e8e&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2fDataBindExtender.cs.txt"&gt;DataBindExtender.cs&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=fa4e996d-ca6f-48d8-bc14-de3caa954e8e" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,fa4e996d-ca6f-48d8-bc14-de3caa954e8e.aspx</comments>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=bd5a8c26-7bf7-4103-8f45-02e0a970efec</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,bd5a8c26-7bf7-4103-8f45-02e0a970efec.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,bd5a8c26-7bf7-4103-8f45-02e0a970efec.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=bd5a8c26-7bf7-4103-8f45-02e0a970efec</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently we were raising a <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;url=http%3a%2f%2fthread.gmane.org%2fgmane.text.xml.xsl.general.mulberrytech%2f80506">question
about serialization of ASPX output in xslt</a>.
</p>
        <p>
The question went like this:
</p>
        <p style="PADDING-LEFT: 1em; FONT-STYLE: italic">
What's the recommended way of ASPX page generation?<br />
E.g.:<br /><br />
------------------------<br />
 &lt;%@ Page AutoEventWireup="true"<br />
   CodeBehind="CurMainMenuP.aspx.cs"<br />
   EnableSessionState="True"<br />
   Inherits="Currency.CurMainMenuP"<br />
   Language="C#"<br />
   MaintainScrollPositionOnPostback="True"<br />
   MasterPageFile="Screen.Master" %&gt;<br /><br />
&lt;asp:Content ID="Content1" runat="server" ContentPlaceHolderID="Title"&gt;CUR_MAIN_MENU_P&lt;/asp:Content&gt;<br /><br />
&lt;asp:Content ID="Content2" runat="server" ContentPlaceHolderID="Content"&gt;<br />
  &lt;span id="id1222146581" runat="server" 
<br />
    class="inputField system UpperCase" enableviewstate="false"&gt;<br />
    &lt;%# Dialog.Global.TranCode %&gt;<br />
  &lt;/span&gt;<br />
  ...<br />
------------------------<br /><br />
Notice aspx page directives, data binding expessions, and prefixed tag names without
namespace declarations.
</p>
        <p>
There was a whole range of expected answers. We, however, looked whether somebody
have already dealed with the task and has a ready solution at hands.
</p>
        <p>
In general it seems that xslt community is very angry about ASPX: both format and
technology. Well, put this aside.
</p>
        <p>
The task of producing ASPX, which is <b>almost</b> xml, is not solvable when you're
staying with pure xml serializer. Xslt's <code><a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-character-map">xsl:character-map</a></code> does
not work at all. In fact it looks as a childish attempt to address the problem, as
it does not support character escapes but only grabs characters and substitutes them
with strings.
</p>
        <p>
We have decided to create ASPX serializer API producing required output text. This
way you use <code>&lt;xsl:output method="text"/&gt;</code> to generate ASPX pages.
</p>
        <p>
With this goal in mind we have defined a little xml schema to describe ASPX irregularities
in xml form. These are:
</p>
        <ul>
          <li>
            <code>&lt;xs:element name="declared-prefix"&gt;</code> - to describe known prefixes,
which should not be declared; 
</li>
          <li>
            <code>&lt;xs:element name="directive"&gt;</code> - to describe directives like &lt;%@
Page %&gt;; 
</li>
          <li>
            <code>&lt;xs:element name="content"&gt;</code> - a transparent content wrapper; 
</li>
          <li>
            <code>&lt;xs:element name="entity"&gt;</code> - to issue xml entity; 
</li>
          <li>
            <code>&lt;xs:element name="expression"&gt;</code> - to describe aspx expression like
&lt;%# Eval("A") %&gt;; 
</li>
          <li>
            <code>&lt;xs:element name="attribute"&gt;</code> - to describe an attribute of the
parent element. 
</li>
        </ul>
        <p>
This approach greately simplified for us an ASPX generation process.
</p>
        <p>
The API includes:
</p>
        <ul>
          <li>
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2faspx.xsd">aspx.xsd</a> -
an xml schema for the ASPX elements; 
</li>
          <li>
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2faspx-serializer.xslt">aspx-serializer.xslt</a> -
a serializer API; 
</li>
          <li>
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2faspx-test.xslt">aspx-test.xslt</a> -
a test stylesheet (any xml input is used). 
</li>
        </ul>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec" />
      </body>
      <title>Xslt serializer for ASPX output</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,bd5a8c26-7bf7-4103-8f45-02e0a970efec.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2010/06/22/XsltSerializerForASPXOutput.aspx</link>
      <pubDate>Tue, 22 Jun 2010 10:25:41 GMT</pubDate>
      <description>&lt;p&gt;
Recently we were raising a &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;amp;url=http%3a%2f%2fthread.gmane.org%2fgmane.text.xml.xsl.general.mulberrytech%2f80506"&gt;question
about serialization of ASPX output in xslt&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The question went like this:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em; FONT-STYLE: italic"&gt;
What's the recommended way of ASPX page generation?&lt;br&gt;
E.g.:&lt;br&gt;
&lt;br&gt;
------------------------&lt;br&gt;
&amp;nbsp;&amp;lt;%@ Page AutoEventWireup="true"&lt;br&gt;
&amp;nbsp;&amp;nbsp; CodeBehind="CurMainMenuP.aspx.cs"&lt;br&gt;
&amp;nbsp;&amp;nbsp; EnableSessionState="True"&lt;br&gt;
&amp;nbsp;&amp;nbsp; Inherits="Currency.CurMainMenuP"&lt;br&gt;
&amp;nbsp;&amp;nbsp; Language="C#"&lt;br&gt;
&amp;nbsp;&amp;nbsp; MaintainScrollPositionOnPostback="True"&lt;br&gt;
&amp;nbsp;&amp;nbsp; MasterPageFile="Screen.Master" %&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;asp:Content ID="Content1" runat="server" ContentPlaceHolderID="Title"&amp;gt;CUR_MAIN_MENU_P&amp;lt;/asp:Content&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;asp:Content ID="Content2" runat="server" ContentPlaceHolderID="Content"&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;span id="id1222146581" runat="server" 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; class="inputField system UpperCase" enableviewstate="false"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;%# Dialog.Global.TranCode %&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;/span&amp;gt;&lt;br&gt;
&amp;nbsp; ...&lt;br&gt;
------------------------&lt;br&gt;
&lt;br&gt;
Notice aspx page directives, data binding expessions, and prefixed tag names without
namespace declarations.
&lt;/p&gt;
&lt;p&gt;
There was a whole range of expected answers. We, however, looked whether somebody
have already dealed with the task and has a ready solution at hands.
&lt;/p&gt;
&lt;p&gt;
In general it seems that xslt community is very angry about ASPX: both format and
technology. Well, put this aside.
&lt;/p&gt;
&lt;p&gt;
The task of producing ASPX, which is &lt;b&gt;almost&lt;/b&gt; xml, is not solvable when you're
staying with pure xml serializer. Xslt's &lt;code&gt;&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-character-map"&gt;xsl:character-map&lt;/a&gt;&lt;/code&gt; does
not work at all. In fact it looks as a childish attempt to address the problem, as
it does not support character escapes but only grabs characters and substitutes them
with strings.
&lt;/p&gt;
&lt;p&gt;
We have decided to create ASPX serializer API producing required output text. This
way you use &lt;code&gt;&amp;lt;xsl:output method="text"/&amp;gt;&lt;/code&gt; to generate ASPX pages.
&lt;/p&gt;
&lt;p&gt;
With this goal in mind we have defined a little xml schema to describe ASPX irregularities
in xml form. These are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;xs:element name="declared-prefix"&amp;gt;&lt;/code&gt; - to describe known prefixes,
which should not be declared; 
&lt;li&gt;
&lt;code&gt;&amp;lt;xs:element name="directive"&amp;gt;&lt;/code&gt; - to describe directives like &amp;lt;%@
Page %&amp;gt;; 
&lt;li&gt;
&lt;code&gt;&amp;lt;xs:element name="content"&amp;gt;&lt;/code&gt; - a transparent content wrapper; 
&lt;li&gt;
&lt;code&gt;&amp;lt;xs:element name="entity"&amp;gt;&lt;/code&gt; - to issue xml entity; 
&lt;li&gt;
&lt;code&gt;&amp;lt;xs:element name="expression"&amp;gt;&lt;/code&gt; - to describe aspx expression like
&amp;lt;%# Eval("A") %&amp;gt;; 
&lt;li&gt;
&lt;code&gt;&amp;lt;xs:element name="attribute"&amp;gt;&lt;/code&gt; - to describe an attribute of the
parent element. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
This approach greately simplified for us an ASPX generation process.
&lt;/p&gt;
&lt;p&gt;
The API includes:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2faspx.xsd"&gt;aspx.xsd&lt;/a&gt; -
an xml schema for the ASPX elements; 
&lt;li&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2faspx-serializer.xslt"&gt;aspx-serializer.xslt&lt;/a&gt; -
a serializer API; 
&lt;li&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2faspx-test.xslt"&gt;aspx-test.xslt&lt;/a&gt; -
a test stylesheet (any xml input is used). 
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=bd5a8c26-7bf7-4103-8f45-02e0a970efec" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,bd5a8c26-7bf7-4103-8f45-02e0a970efec.aspx</comments>
      <category>Announce</category>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=7e8aa28f-3674-44ae-bf81-a8b042ca4c23</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7e8aa28f-3674-44ae-bf81-a8b042ca4c23.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7e8aa28f-3674-44ae-bf81-a8b042ca4c23.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7e8aa28f-3674-44ae-bf81-a8b042ca4c23</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In previous posts we were crying about problems with JSF to ASP.NET migration. Let's
point to another one.
</p>
        <p>
Consider that you have an input field, whose value should be validated:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;input type="text" runat="server" ID="id1222146409" maxlength="4"/&gt;<br />
&lt;bphx:DataBindExtender runat="server" 
<br />
  TargetControlID="id1222146409" ControlProperty="Value" 
<br />
  DataSource="&lt;%# Import.AaControlAttributes %&gt;" 
<br />
  DataMember="UserEnteredTrancode"/&gt; </code>
        </p>
        <p>
Here we have an input control, whose value is bound to <code>Import.AaControlAttributes.UserEnteredTrancode</code> property.
But what is missed is a value validation. Somewhere we have a function that could
answer the question whether the value is valid. It should be called like this: <code>Functions.IsTransactionCodeValid(value)</code>.
</p>
        <p>
Staying within standard components we can use a custom validator on the page:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;asp:CustomValidator runat="server" 
<br />
  ControlToValidate="id1222146409" 
<br />
  OnServerValidate="ValidateTransaction" 
<br />
  ErrorMessage="Invalid transaction code."/&gt;</code>
        </p>
        <p>
and add the following code-behind:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>protected void ValidateTransaction(object source, ServerValidateEventArgs args)<br />
{ 
<br />
  args.IsValid = Functions.IsTransactionCodeValid(args.Value);<br />
}</code>
        </p>
        <p>
This approach works, however it pollutes the code-behind with many very similar methods.
The problem is that the validation rules in most cases are not property of page but
one of data model. That's why page validation methods just forward check to somewhere.
</p>
        <p>
While thinking on how to simplify the code we have came up with more conscious and
short way to express validators, namely using lambda functions. To that end we have
introduced a <code>Validator</code> property of type <code>ValueValidator</code> over <code>DataBindExtender</code>.
Where
</p>
        <p style="PADDING-LEFT: 1em">
          <code>/// &lt;summary&gt;A delegate to validate values.&lt;/summary&gt;<br />
/// &lt;param name="extender"&gt;An extender instance.&lt;/param&gt;<br />
/// &lt;param name="value"&gt;A value to validate.&lt;/param&gt;<br />
/// &lt;returns&gt;true for valid value, and false otherwise.&lt;/returns&gt;<br />
public delegate bool ValueValidator(DataBindExtender extender, object value);<br /><br />
/// &lt;summary&gt;An optional data member validator.&lt;/summary&gt;<br />
public virtual ValueValidator Validator { get; set; } </code>
        </p>
        <p>
With this new property the page markup looks like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;input type="text" runat="server" ID="id1222146409" maxlength="4"/&gt;<br />
&lt;bphx:DataBindExtender runat="server" 
<br />
  TargetControlID="id1222146409" ControlProperty="Value" 
<br />
  DataSource="&lt;%# Import.AaControlAttributes %&gt;" 
<br />
  DataMember="UserEnteredTrancode" 
<br />
  <b>Validator='&lt;%# (extender, value) =&gt; Functions.IsTransactionCodeValid(value
as string) %&gt;'</b><br />
  ErrorMessage="Invalid transaction code."/&gt; </code>
        </p>
        <p>
This is almost like an event handler, however it allowed us to call data model validation
logic without unnecessary code-behind. 
</p>
        <p>
The updated <code>DataBindExtender</code> can be found at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7e8aa28f-3674-44ae-bf81-a8b042ca4c23&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2fDataBindExtender.cs.txt">DataBindExtender.cs</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7e8aa28f-3674-44ae-bf81-a8b042ca4c23" />
      </body>
      <title>Validators in ASP.NET</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7e8aa28f-3674-44ae-bf81-a8b042ca4c23.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2010/06/15/ValidatorsInASPNET.aspx</link>
      <pubDate>Tue, 15 Jun 2010 06:36:44 GMT</pubDate>
      <description>&lt;p&gt;
In previous posts we were crying about problems with JSF to ASP.NET migration. Let's
point to another one.
&lt;/p&gt;
&lt;p&gt;
Consider that you have an input field, whose value should be validated:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;input type="text" runat="server" ID="id1222146409" maxlength="4"/&amp;gt;&lt;br&gt;
&amp;lt;bphx:DataBindExtender runat="server" 
&lt;br&gt;
&amp;nbsp; TargetControlID="id1222146409" ControlProperty="Value" 
&lt;br&gt;
&amp;nbsp; DataSource="&amp;lt;%# Import.AaControlAttributes %&amp;gt;" 
&lt;br&gt;
&amp;nbsp; DataMember="UserEnteredTrancode"/&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Here we have an input control, whose value is bound to &lt;code&gt;Import.AaControlAttributes.UserEnteredTrancode&lt;/code&gt; property.
But what is missed is a value validation. Somewhere we have a function that could
answer the question whether the value is valid. It should be called like this: &lt;code&gt;Functions.IsTransactionCodeValid(value)&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
Staying within standard components we can use a custom validator on the page:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;asp:CustomValidator runat="server" 
&lt;br&gt;
&amp;nbsp; ControlToValidate="id1222146409" 
&lt;br&gt;
&amp;nbsp; OnServerValidate="ValidateTransaction" 
&lt;br&gt;
&amp;nbsp; ErrorMessage="Invalid transaction code."/&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
and add the following code-behind:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;protected void ValidateTransaction(object source, ServerValidateEventArgs args)&lt;br&gt;
{ 
&lt;br&gt;
&amp;nbsp; args.IsValid = Functions.IsTransactionCodeValid(args.Value);&lt;br&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
This approach works, however it pollutes the code-behind with many very similar methods.
The problem is that the validation rules in most cases are not property of page but
one of data model. That's why page validation methods just forward check to somewhere.
&lt;/p&gt;
&lt;p&gt;
While thinking on how to simplify the code we have came up with more conscious and
short way to express validators, namely using lambda functions. To that end we have
introduced a &lt;code&gt;Validator&lt;/code&gt; property of type &lt;code&gt;ValueValidator&lt;/code&gt; over &lt;code&gt;DataBindExtender&lt;/code&gt;.
Where
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;/// &amp;lt;summary&amp;gt;A delegate to validate values.&amp;lt;/summary&amp;gt;&lt;br&gt;
/// &amp;lt;param name="extender"&amp;gt;An extender instance.&amp;lt;/param&amp;gt;&lt;br&gt;
/// &amp;lt;param name="value"&amp;gt;A value to validate.&amp;lt;/param&amp;gt;&lt;br&gt;
/// &amp;lt;returns&amp;gt;true for valid value, and false otherwise.&amp;lt;/returns&amp;gt;&lt;br&gt;
public delegate bool ValueValidator(DataBindExtender extender, object value);&lt;br&gt;
&lt;br&gt;
/// &amp;lt;summary&amp;gt;An optional data member validator.&amp;lt;/summary&amp;gt;&lt;br&gt;
public virtual ValueValidator Validator { get; set; } &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
With this new property the page markup looks like this:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;input type="text" runat="server" ID="id1222146409" maxlength="4"/&amp;gt;&lt;br&gt;
&amp;lt;bphx:DataBindExtender runat="server" 
&lt;br&gt;
&amp;nbsp; TargetControlID="id1222146409" ControlProperty="Value" 
&lt;br&gt;
&amp;nbsp; DataSource="&amp;lt;%# Import.AaControlAttributes %&amp;gt;" 
&lt;br&gt;
&amp;nbsp; DataMember="UserEnteredTrancode" 
&lt;br&gt;
&amp;nbsp; &lt;b&gt;Validator='&amp;lt;%# (extender, value) =&amp;gt; Functions.IsTransactionCodeValid(value
as string) %&amp;gt;'&lt;/b&gt; 
&lt;br&gt;
&amp;nbsp; ErrorMessage="Invalid transaction code."/&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
This is almost like an event handler, however it allowed us to call data model validation
logic without unnecessary code-behind. 
&lt;/p&gt;
&lt;p&gt;
The updated &lt;code&gt;DataBindExtender&lt;/code&gt; can be found at &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7e8aa28f-3674-44ae-bf81-a8b042ca4c23&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2fDataBindExtender.cs.txt"&gt;DataBindExtender.cs&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7e8aa28f-3674-44ae-bf81-a8b042ca4c23" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7e8aa28f-3674-44ae-bf81-a8b042ca4c23.aspx</comments>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ce7277f4-844b-4fef-8892-599a5e3b6a95</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ce7277f4-844b-4fef-8892-599a5e3b6a95.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ce7277f4-844b-4fef-8892-599a5e3b6a95.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ce7277f4-844b-4fef-8892-599a5e3b6a95</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Being well behind of the latest news and traps of the ASP.NET, we're readily falling
on each problem. :-)
</p>
        <p>
This time it's a script injection during data binding. 
</p>
        <p>
In JSF there is a component to output data called <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95&amp;url=http%3a%2f%2fjava.sun.com%2fjavaee%2fjavaserverfaces%2f1.2_MR1%2fdocs%2ftlddocs%2fh%2foutputText.html">h:outputText</a>.
Its use is like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;span jsfc="h:outputText" value="#{myBean.myProperty}"/&gt;</code>
        </p>
        <p>
The output is a span element with data bound value embeded into content. The natural
alternative in ASP.NET seems to be an <code>asp:Label</code> control:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;asp:Label runat="server" Text="&lt;%# Eval("MyProperty") %&gt;"/&gt;</code>
        </p>
        <p>
This almost works except that the <code>h:outputText</code> escapes data (you may
override this and specify attribute <code>escape="false"</code>), and <code>asp:Label</code> never
escapes the data. 
</p>
        <p>
This looks as a very serious omission in ASP.NET (in fact very close to a security
hole). What are chances that when you're creating a new page, which uses data binding,
you will not forget to fix code that wizard created for you and to change it to:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;asp:Label runat="server" Text="&lt;%# <span>Server.HtmlEncode(Eval(</span>"MyProperty"))
%&gt;"/&gt;</code>
        </p>
        <p>
Eh? Think what will happen if <code>MyProperty</code> will return a text that looks
like a script (e.g.: <code>&lt;script&gt;alert(1)&lt;/script&gt;</code>), while you
just wanted to output a label?
</p>
        <p>
To address the issue we've also introduced a property Escape into <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2fDataBindExtender.cs.txt">DataBindExtender</a>.
So at present we have a code like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;asp:Label runat="server" ID="MyLabel"/&gt;<br />
&lt;bphx:DataBindExtender runat="server" TargetControlID="MyLabel" 
<br />
  ControlProperty="Text" ReadOnly="true" <b>Escape="true"</b><br />
  DataSource="&lt;%# MyBean %&gt;" DataMember="MyProperty"/&gt;</code>
        </p>
        <p>
See also: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f06%2f05%2fADataBindExtender.aspx">A
DataBindExtender</a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f05%2f29%2fExperienceOfJSFToASPNETMigration.aspx">Experience
of JSF to ASP.NET migration</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95" />
      </body>
      <title>Data dinding script injection in ASP.NET</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ce7277f4-844b-4fef-8892-599a5e3b6a95.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2010/06/10/DataDindingScriptInjectionInASPNET.aspx</link>
      <pubDate>Thu, 10 Jun 2010 13:06:19 GMT</pubDate>
      <description>&lt;p&gt;
Being well behind of the latest news and traps of the ASP.NET, we're readily falling
on each problem. :-)
&lt;/p&gt;
&lt;p&gt;
This time it's a script injection during data binding. 
&lt;/p&gt;
&lt;p&gt;
In JSF there is a component to output data called &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95&amp;amp;url=http%3a%2f%2fjava.sun.com%2fjavaee%2fjavaserverfaces%2f1.2_MR1%2fdocs%2ftlddocs%2fh%2foutputText.html"&gt;h:outputText&lt;/a&gt;.
Its use is like this:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;span jsfc="h:outputText" value="#{myBean.myProperty}"/&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
The output is a span element with data bound value embeded into content. The natural
alternative in ASP.NET seems to be an &lt;code&gt;asp:Label&lt;/code&gt; control:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;asp:Label runat="server" Text="&amp;lt;%# Eval("MyProperty") %&amp;gt;"/&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
This almost works except that the &lt;code&gt;h:outputText&lt;/code&gt; escapes data (you may
override this and specify attribute &lt;code&gt;escape="false"&lt;/code&gt;), and &lt;code&gt;asp:Label&lt;/code&gt; never
escapes the data. 
&lt;/p&gt;
&lt;p&gt;
This looks as a very serious omission in ASP.NET (in fact very close to a security
hole). What are chances that when you're creating a new page, which uses data binding,
you will not forget to fix code that wizard created for you and to change it to:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;asp:Label runat="server" Text="&amp;lt;%# &lt;span&gt;Server.HtmlEncode(Eval(&lt;/span&gt;"MyProperty"))
%&amp;gt;"/&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Eh? Think what will happen if &lt;code&gt;MyProperty&lt;/code&gt; will return a text that looks
like a script (e.g.: &lt;code&gt;&amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;&lt;/code&gt;), while you
just wanted to output a label?
&lt;/p&gt;
&lt;p&gt;
To address the issue we've also introduced a property Escape into &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2fDataBindExtender.cs.txt"&gt;DataBindExtender&lt;/a&gt;.
So at present we have a code like this:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;asp:Label runat="server" ID="MyLabel"/&amp;gt;&lt;br&gt;
&amp;lt;bphx:DataBindExtender runat="server" TargetControlID="MyLabel" 
&lt;br&gt;
&amp;nbsp; ControlProperty="Text" ReadOnly="true" &lt;b&gt;Escape="true"&lt;/b&gt;
&lt;br&gt;
&amp;nbsp; DataSource="&amp;lt;%# MyBean %&amp;gt;" DataMember="MyProperty"/&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
See also: &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f06%2f05%2fADataBindExtender.aspx"&gt;A
DataBindExtender&lt;/a&gt;, &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f05%2f29%2fExperienceOfJSFToASPNETMigration.aspx"&gt;Experience
of JSF to ASP.NET migration&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ce7277f4-844b-4fef-8892-599a5e3b6a95" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ce7277f4-844b-4fef-8892-599a5e3b6a95.aspx</comments>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=1ad6baf3-8228-4b4d-822a-d0140bb9050c</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,1ad6baf3-8228-4b4d-822a-d0140bb9050c.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,1ad6baf3-8228-4b4d-822a-d0140bb9050c.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=1ad6baf3-8228-4b4d-822a-d0140bb9050c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
After struggling with <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1ad6baf3-8228-4b4d-822a-d0140bb9050c&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f05%2f29%2fExperienceOfJSFToASPNETMigration.aspx">ASP.NET
data binding</a> we found no other way but to introduce our little extender control
to address the issue.
</p>
        <p>
We were trying to be minimalistic and to introduce two way data binding and to support
data conversion. This way extender control (called <code>DataBindExtender</code>)
have following page syntax:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;asp:TextBox id=TextBox1 runat="server"&gt;&lt;/asp:TextBox&gt;<br />
&lt;cc1:DataBindExtender runat="server" 
<br />
  DataSource="&lt;%# Data %&gt;"<br />
  DataMember="ID" 
<br />
  TargetControlID="TextBox1"<br />
  ControlProperty="Text" /&gt; </code>
        </p>
        <p>
Two way data binding is provided with <code>DataSource</code> object (notice data
binding over this property) and a <code>DataMember</code> property from the one side,
and <code>TargetControlID</code> and <code>ControlProperty</code> from the other side. <code>DataBindExtender</code> supports <code>Converter</code> property
of type <code>TypeConverter</code> to support custom converters.
</p>
        <p>
          <code>DataBindExtender</code> is based on <code>AjaxControlToolkit.ExtenderControlBase</code> class
and implements <code>System.Web.UI.IValidator</code>. <code>ExtenderControlBase</code> makes
implementation of extenders extremely easy, while <code>IValidator</code> plugs natuarally
into page validation (<code>Validate</code> method, <code>Validators</code> collections, <code>ValidationSummary</code> control).
</p>
        <p>
The good point about extenders is that they are not visible in designer, while it
exposes properties in extended control itself. The disadvantage is that it requires <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1ad6baf3-8228-4b4d-822a-d0140bb9050c&amp;url=http%3a%2f%2fwww.asp.net%2fajaxlibrary%2fact.ashx">Ajax
Control Toolkit</a>, and also <code>ScriptManager</code> component of the page.
</p>
        <p>
To simplify the use <code>DataBindExtender</code> gets data from control and puts
the value into data source in <code>Validate</code> method, and puts data into control
in <code>OnPreRender</code> method; thus no specific action is required to perform
data binding.
</p>
        <p>
Source for the <code>DataBindExtender</code> is <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1ad6baf3-8228-4b4d-822a-d0140bb9050c&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2fDataBindExtender.cs.txt">DataBindExtender.cs</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=1ad6baf3-8228-4b4d-822a-d0140bb9050c" />
      </body>
      <title>A DataBindExtender: two way databinding in ASP.NET</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,1ad6baf3-8228-4b4d-822a-d0140bb9050c.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2010/06/05/ADataBindExtenderTwoWayDatabindingInASPNET.aspx</link>
      <pubDate>Sat, 05 Jun 2010 11:22:03 GMT</pubDate>
      <description>&lt;p&gt;
After struggling with &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1ad6baf3-8228-4b4d-822a-d0140bb9050c&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f05%2f29%2fExperienceOfJSFToASPNETMigration.aspx"&gt;ASP.NET
data binding&lt;/a&gt; we found no other way but to introduce our little extender control
to address the issue.
&lt;/p&gt;
&lt;p&gt;
We were trying to be minimalistic and to introduce two way data binding and to support
data conversion. This way extender control (called &lt;code&gt;DataBindExtender&lt;/code&gt;)
have following page syntax:
&lt;/p&gt;
&lt;p style="PADDING-LEFT: 1em"&gt;
&lt;code&gt;&amp;lt;asp:TextBox id=TextBox1 runat="server"&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br&gt;
&amp;lt;cc1:DataBindExtender runat="server" 
&lt;br&gt;
&amp;nbsp; DataSource="&amp;lt;%# Data %&amp;gt;"&lt;br&gt;
&amp;nbsp; DataMember="ID" 
&lt;br&gt;
&amp;nbsp; TargetControlID="TextBox1"&lt;br&gt;
&amp;nbsp; ControlProperty="Text" /&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Two way data binding is provided with &lt;code&gt;DataSource&lt;/code&gt; object (notice data
binding over this property) and a &lt;code&gt;DataMember&lt;/code&gt; property from the one side,
and &lt;code&gt;TargetControlID&lt;/code&gt; and &lt;code&gt;ControlProperty&lt;/code&gt; from the other side. &lt;code&gt;DataBindExtender&lt;/code&gt; supports &lt;code&gt;Converter&lt;/code&gt; property
of type &lt;code&gt;TypeConverter&lt;/code&gt; to support custom converters.
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;DataBindExtender&lt;/code&gt; is based on &lt;code&gt;AjaxControlToolkit.ExtenderControlBase&lt;/code&gt; class
and implements &lt;code&gt;System.Web.UI.IValidator&lt;/code&gt;. &lt;code&gt;ExtenderControlBase&lt;/code&gt; makes
implementation of extenders extremely easy, while &lt;code&gt;IValidator&lt;/code&gt; plugs natuarally
into page validation (&lt;code&gt;Validate&lt;/code&gt; method, &lt;code&gt;Validators&lt;/code&gt; collections, &lt;code&gt;ValidationSummary&lt;/code&gt; control).
&lt;/p&gt;
&lt;p&gt;
The good point about extenders is that they are not visible in designer, while it
exposes properties in extended control itself. The disadvantage is that it requires &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1ad6baf3-8228-4b4d-822a-d0140bb9050c&amp;amp;url=http%3a%2f%2fwww.asp.net%2fajaxlibrary%2fact.ashx"&gt;Ajax
Control Toolkit&lt;/a&gt;, and also &lt;code&gt;ScriptManager&lt;/code&gt; component of the page.
&lt;/p&gt;
&lt;p&gt;
To simplify the use &lt;code&gt;DataBindExtender&lt;/code&gt; gets data from control and puts
the value into data source in &lt;code&gt;Validate&lt;/code&gt; method, and puts data into control
in &lt;code&gt;OnPreRender&lt;/code&gt; method; thus no specific action is required to perform
data binding.
&lt;/p&gt;
&lt;p&gt;
Source for the &lt;code&gt;DataBindExtender&lt;/code&gt; is &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1ad6baf3-8228-4b4d-822a-d0140bb9050c&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fasp.net%2fDataBindExtender.cs.txt"&gt;DataBindExtender.cs&lt;/a&gt;.
&lt;/p&gt;
&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=1ad6baf3-8228-4b4d-822a-d0140bb9050c" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,1ad6baf3-8228-4b4d-822a-d0140bb9050c.aspx</comments>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ecf2ba02-c98c-4f03-9e7e-61db7822ed32</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ecf2ba02-c98c-4f03-9e7e-61db7822ed32.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ecf2ba02-c98c-4f03-9e7e-61db7822ed32.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ecf2ba02-c98c-4f03-9e7e-61db7822ed32</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We used to think that ASP.NET is a way too powerful than JSF. It might be still true,
but not when you are accustomed to JSF and spoiled with its code practice...
</p>
        <p>
Looking at both technologies from a greater distance, we now realize that they give
almost the same level of comfort during development, but they are different. You can
feel this after you were working for some time with one technology and now are to
implement similar solution in opposite one. That is where we have found ourselves
at present.
</p>
        <p>
The funny thing is that we did expect some problems but in a different place. Indeed,
both ASP.NET and JSF are means to define a page layout and to map input and output
of business data. While with the presentation (controls, their compositions, masters,
styles and so on) you can find more or less equal analogies, the differences of implementation
of data binding is a kind of a pain.
</p>
        <p>
We have found that data binding in ASP.NET is somewhat awkward. Its <code>Eval</code> and <code>Bind</code> is
bearable in simple cases but almost unusable when you business data is less trivial,
or if you have to apply custom data formatting.
</p>
        <p>
In JSF, with its Expression Language, we can perform two way data binding for rather
complex properties like <code>${data.items[index + 5].property}</code>, or to create
property adapters <code>${my:asSomething(data.bean, "property").Value}</code>, or
add standard or custom property converters. In contrast data binding in ASP.NET is
limited to simple property path (no expressions are supported), neither custom formatters
are supported (try to format number as a telephone number).
</p>
        <p>
Things work well when you're designing ASP.NET application from scratch, as you naturally
avoid pitfalls, however when you got existing business logic and need to expose it
to the web, you have no other way but to write a lot of code behind just to smooth
out the problems that ASP.NET exhibits.
</p>
        <p>
Another solution would be to design something like extender control that would attach
more proper data binding and formatting facilities to control properties. That would
allow to make page definitions in more declarative way, like what we have now in JSF.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ecf2ba02-c98c-4f03-9e7e-61db7822ed32" />
      </body>
      <title>Experience of JSF to ASP.NET migration</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ecf2ba02-c98c-4f03-9e7e-61db7822ed32.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2010/05/29/ExperienceOfJSFToASPNETMigration.aspx</link>
      <pubDate>Sat, 29 May 2010 14:16:05 GMT</pubDate>
      <description>&lt;p&gt;
We used to think that ASP.NET is a way too powerful than JSF. It might be still true,
but not when you are accustomed to JSF and spoiled with its code practice...
&lt;/p&gt;
&lt;p&gt;
Looking at both technologies from a greater distance, we now realize that they give
almost the same level of comfort during development, but they are different. You can
feel this after you were working for some time with one technology and now are to
implement similar solution in opposite one. That is where we have found ourselves
at present.
&lt;/p&gt;
&lt;p&gt;
The funny thing is that we did expect some problems but in a different place. Indeed,
both ASP.NET and JSF are means to define a page layout and to map input and output
of business data. While with the presentation (controls, their compositions, masters,
styles and so on) you can find more or less equal analogies, the differences of implementation
of data binding is a kind of a pain.
&lt;/p&gt;
&lt;p&gt;
We have found that data binding in ASP.NET is somewhat awkward. Its &lt;code&gt;Eval&lt;/code&gt; and &lt;code&gt;Bind&lt;/code&gt; is
bearable in simple cases but almost unusable when you business data is less trivial,
or if you have to apply custom data formatting.
&lt;/p&gt;
&lt;p&gt;
In JSF, with its Expression Language, we can perform two way data binding for rather
complex properties like &lt;code&gt;${data.items[index + 5].property}&lt;/code&gt;, or to create
property adapters &lt;code&gt;${my:asSomething(data.bean, "property").Value}&lt;/code&gt;, or
add standard or custom property converters. In contrast data binding in ASP.NET is
limited to simple property path (no expressions are supported), neither custom formatters
are supported (try to format number as a telephone number).
&lt;/p&gt;
&lt;p&gt;
Things work well when you're designing ASP.NET application from scratch, as you naturally
avoid pitfalls, however when you got existing business logic and need to expose it
to the web, you have no other way but to write a lot of code behind just to smooth
out the problems that ASP.NET exhibits.
&lt;/p&gt;
&lt;p&gt;
Another solution would be to design something like extender control that would attach
more proper data binding and formatting facilities to control properties. That would
allow to make page definitions in more declarative way, like what we have now in JSF.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ecf2ba02-c98c-4f03-9e7e-61db7822ed32" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ecf2ba02-c98c-4f03-9e7e-61db7822ed32.aspx</comments>
      <category>ASP.NET</category>
      <category>JSF and Facelets</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=20b8a446-14a7-4070-b6e1-fe990e5ae9a8</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,20b8a446-14a7-4070-b6e1-fe990e5ae9a8.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,20b8a446-14a7-4070-b6e1-fe990e5ae9a8.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=20b8a446-14a7-4070-b6e1-fe990e5ae9a8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While porting a solution from JSF to ASP.NET we have seen an issue with synchronization
of access to a data stored in a session from multiple requests.
</p>
        <p>
Consider a case when you store a business object in a session.
</p>
        <p>
Going through the request lifecycle we observe that this business object may be accessed
at different stages: data binding, postback event handler, security filters, other.
</p>
        <p>
Usually this business object is mutable and does not assume concurent access. Browsers,
however, may easily issue multiple requests to the same session at the same time.
In fact, such behaviour, is not even an exception, as browsers nowadays are often
sending concurrent requests.
</p>
        <p>
In the JSF we're using a sync object, which is part of business object itself; lock
it and unlock at the begin and at the end of a request correspondingly. This works
perfectly as JSF guarantees that:
</p>
        <ul>
          <li>
lock is released after it's acquired (we use request scope bean with <code>@PostConstruct</code> and <code>@PreDestroy</code> annotations
to lock and unlock); 
</li>
          <li>
both lock and unlock take place in the same thread. 
</li>
        </ul>
        <p style="TEXT-DECORATION: line-through">
ASP.NET, in contrast, tries to be more asynchronous, and allows for different stages
of request to take place in different threads. This could be seen indirectly in the
documentation, which does not give any commitments in this regards, and with code
inspection where you can see that request can begin in one thread, and a next stage
can be queued for the execution into the other thread.
</p>
        <p>
          <span style="TEXT-DECORATION: line-through">In addition, </span>ASP.NET does not guarantee
that if <code>BeginRequest</code> has been executed then <code>EndRequest</code> will
also run.
</p>
        <p style="TEXT-DECORATION: line-through">
The conclusion is that we should not use locks to synchronize access to the same session
object, but rather try to invent other means to avoid data races.
</p>
        <p>
          <b>Update</b>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=20b8a446-14a7-4070-b6e1-fe990e5ae9a8&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fms178581.aspx">msdn
states</a>:
</p>
        <div style="PADDING-LEFT: 1em; FONT-STYLE: italic">
          <p>
            <b>Concurrent Requests and Session State</b>
          </p>
          <p>
Access to ASP.NET session state is exclusive per session, which means that if two
different users make concurrent requests, access to each separate session is granted
concurrently. However, if two concurrent requests are made for the same session (by
using the same SessionID value), the first request gets exclusive access to the session
information. The second request executes only after the first request is finished.
(The second session can also get access if the exclusive lock on the information is
freed because the first request exceeds the lock time-out.)
</p>
        </div>
        <p>
This means that the required synchronization is already built into ASP.NET. That's
good.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=20b8a446-14a7-4070-b6e1-fe990e5ae9a8" />
      </body>
      <title>Synchronization of access within a session in ASP.NET</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,20b8a446-14a7-4070-b6e1-fe990e5ae9a8.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2010/05/23/SynchronizationOfAccessWithinASessionInASPNET.aspx</link>
      <pubDate>Sun, 23 May 2010 12:22:35 GMT</pubDate>
      <description>&lt;p&gt;
While porting a solution from JSF to ASP.NET we have seen an issue with synchronization
of access to a data stored in a session from multiple requests.
&lt;/p&gt;
&lt;p&gt;
Consider a case when you store a business object in a session.
&lt;/p&gt;
&lt;p&gt;
Going through the request lifecycle we observe that this business object may be accessed
at different stages: data binding, postback event handler, security filters, other.
&lt;/p&gt;
&lt;p&gt;
Usually this business object is mutable and does not assume concurent access. Browsers,
however, may easily issue multiple requests to the same session at the same time.
In fact, such behaviour, is not even an exception, as browsers nowadays are often
sending concurrent requests.
&lt;/p&gt;
&lt;p&gt;
In the JSF we're using a sync object, which is part of business object itself; lock
it and unlock at the begin and at the end of a request correspondingly. This works
perfectly as JSF guarantees that:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
lock is released after it's acquired (we use request scope bean with &lt;code&gt;@PostConstruct&lt;/code&gt; and &lt;code&gt;@PreDestroy&lt;/code&gt; annotations
to lock and unlock); 
&lt;li&gt;
both lock and unlock take place in the same thread. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="TEXT-DECORATION: line-through"&gt;
ASP.NET, in contrast, tries to be more asynchronous, and allows for different stages
of request to take place in different threads. This could be seen indirectly in the
documentation, which does not give any commitments in this regards, and with code
inspection where you can see that request can begin in one thread, and a next stage
can be queued for the execution into the other thread.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="TEXT-DECORATION: line-through"&gt;In addition, &lt;/span&gt;ASP.NET does not guarantee
that if &lt;code&gt;BeginRequest&lt;/code&gt; has been executed then &lt;code&gt;EndRequest&lt;/code&gt; will
also run.
&lt;/p&gt;
&lt;p style="TEXT-DECORATION: line-through"&gt;
The conclusion is that we should not use locks to synchronize access to the same session
object, but rather try to invent other means to avoid data races.
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Update&lt;/b&gt; &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=20b8a446-14a7-4070-b6e1-fe990e5ae9a8&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fms178581.aspx"&gt;msdn
states&lt;/a&gt;:
&lt;/p&gt;
&lt;div style="PADDING-LEFT: 1em; FONT-STYLE: italic"&gt;
&lt;p&gt;
&lt;b&gt;Concurrent Requests and Session State&lt;/b&gt;
&lt;/p&gt;
&lt;p&gt;
Access to ASP.NET session state is exclusive per session, which means that if two
different users make concurrent requests, access to each separate session is granted
concurrently. However, if two concurrent requests are made for the same session (by
using the same SessionID value), the first request gets exclusive access to the session
information. The second request executes only after the first request is finished.
(The second session can also get access if the exclusive lock on the information is
freed because the first request exceeds the lock time-out.)
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
This means that the required synchronization is already built into ASP.NET. That's
good.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=20b8a446-14a7-4070-b6e1-fe990e5ae9a8" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,20b8a446-14a7-4070-b6e1-fe990e5ae9a8.aspx</comments>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
    </item>
  </channel>
</rss>