<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" 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:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  <id>http://www.icodefactory.com/lab/</id>
  <title>ICF Labs</title>
  <updated>2010-07-13T04:14:45+00:00</updated>
  <link href="http://www.icodefactory.com/lab/" />
  
  <subtitle>Stories from ICodeFactory labs. What we have found, investigated, experienced or just marked interesting while developing our software solutions.</subtitle>
  <author>
    <name>ICodeFactory Labs</name>
  </author>
  <generator uri="http://dotnetblogengine.net/" version="1.0.0.0">BlogEngine.Net Syndication Generator</generator>
  <blogChannel:blogRoll>http://www.icodefactory.com/lab/opml.axd</blogChannel:blogRoll>
  <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
  <dc:creator>ICodeFactory Labs</dc:creator>
  <dc:description>Stories from ICodeFactory labs. What we have found, investigated, experienced or just marked interesting while developing our software solutions.</dc:description>
  <dc:language>en-US</dc:language>
  <dc:title>ICF Labs</dc:title>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/icodefactory" /><feedburner:info uri="icodefactory" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <id>http://www.icodefactory.com/lab/post/Workaround-for-removing-broken-VSTO-bookmark-object-after-manual-removal-from-the-document.aspx</id>
    <title>Workaround for removing broken VSTO bookmark object after manual removal from the document</title>
    <updated>2010-07-13T04:14:45+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=8c5cb914-00b0-4354-b3ba-ddf33d6a1d09" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/47M9q-yfO00/Workaround-for-removing-broken-VSTO-bookmark-object-after-manual-removal-from-the-document.aspx" />
    <author>
      <name>Janko</name>
    </author>
    <summary type="html">&lt;blockquote&gt;   &lt;p&gt;Bookmarks are very useful in developing and working with documents. Besides content controls, they are the main tool for our Word add-in project and are used as placeholders to mark items or locations in the Word document. Although developers would like bookmarks to have more options and operations like content controls, they are just not as flexible. Some options that could be supported by VSTO 3 but, unfortunately are not, could make our lives as developers easier:&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;before delete and after add events,&lt;/li&gt;    &lt;li&gt;locking bookmark to prevent deleting,&lt;/li&gt;    &lt;li&gt;locking bookmark and its content,&lt;/li&gt;    &lt;li&gt;deleting bookmark with its content…&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;All these options are supported for content controls.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This post is about a problem that exists when user deletes a bookmark from the document manually. There is no event triggered when this happens. Deleting bookmarks manually causes its &lt;em&gt;&lt;strong&gt;Interop.Word.Bookmark&lt;/strong&gt;&lt;/em&gt; object to be removed, but &lt;em&gt;&lt;strong&gt;Tools.Word.Bookmark&lt;/strong&gt;&lt;/em&gt; object remains in the documents controls collection. We can access this remaining object but access to its properties and methods will throw exception with message &amp;quot;Object has been deleted&amp;quot;. In this state it can not even be removed from the document.Controls collection. So if user removes the bookmark manually, our application will be unaware of that and will break when trying to access its properties, methods or even to remove it.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Fortunately, there is a way to “repair” this broken &lt;em&gt;&lt;strong&gt;Tools.Word.Bookmark&lt;/strong&gt;&lt;/em&gt; object enough for us be able to remove it from the collection of document’s VSTO objects. Then we are able to recover our application from this unwanted user action. Every time we want to get any bookmarks we use the following method:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; GetBookmarkIfExists(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; bookmarkName &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;) _ 
                                    &lt;span class="kwrd"&gt;As&lt;/span&gt; Tools.Word.Bookmark
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; returningControl &lt;span class="kwrd"&gt;As&lt;/span&gt; Tools.Word.Bookmark = &lt;span class="kwrd"&gt;Nothing&lt;/span&gt;
       
        &lt;span class="rem"&gt;' If bookmark exists in word document, get it:&lt;/span&gt;
        &lt;span class="kwrd"&gt;If&lt;/span&gt; &lt;span class="kwrd"&gt;Me&lt;/span&gt;.Controls.Contains(bookmarkName) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            returningControl = &lt;span class="kwrd"&gt;Me&lt;/span&gt;.Controls(bookmarkName)

            &lt;span class="rem"&gt;' If user has deleted bookmark manually, VSTO object exists but interop&lt;/span&gt;
            &lt;span class="rem"&gt;' not. To recover from this unwanted state it is needed to remove VSTO&lt;/span&gt;
            &lt;span class="rem"&gt;' object too:&lt;/span&gt;
            &lt;span class="kwrd"&gt;If&lt;/span&gt; (&lt;span class="kwrd"&gt;Not&lt;/span&gt; (Globals.ThisDocument.Bookmarks.Exists(bookmarkName))) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                Globals.ThisDocument.Bookmarks.Add(bookmarkName, &lt;span class="kwrd"&gt;Me&lt;/span&gt;.Range(0, 0))

                &lt;span class="rem"&gt;' Remove all bindings from the bookmark and delete it:&lt;/span&gt;
                returningControl.DataBindings.Clear()
                returningControl.Delete()
              
                returningControl = &lt;span class="kwrd"&gt;Nothing&lt;/span&gt;
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; returningControl 
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;The method is in the document class.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This method checks if the corresponding Interop object exists for the VSTO object. If not, the VSTO object it broken. By adding interop object with the same name, VSTO object will be “repaired”. Range of repaired bookmark will not be as it was before removal but it is deletable now. Deleting bookmark will not delete its content.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Of course this method needs to be adapted to your code and application.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/47M9q-yfO00" height="1" width="1"/&gt;</summary>
    <published>2010-07-13T04:14:45+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/Workaround-for-removing-broken-VSTO-bookmark-object-after-manual-removal-from-the-document.aspx#comment" />
    <category term="VSTO" />
    <category term=".NET" />
    <dc:publisher>Janko</dc:publisher>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=8c5cb914-00b0-4354-b3ba-ddf33d6a1d09</pingback:target>
    <slash:comments>51</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=8c5cb914-00b0-4354-b3ba-ddf33d6a1d09</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/Workaround-for-removing-broken-VSTO-bookmark-object-after-manual-removal-from-the-document.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=8c5cb914-00b0-4354-b3ba-ddf33d6a1d09</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/Workaround-for-removing-broken-VSTO-bookmark-object-after-manual-removal-from-the-document.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/Workaround-for-VSTO-bug-Content-control-Exiting-event-handler.aspx</id>
    <title>Workaround for VSTO bug: Content control Exiting event handler</title>
    <updated>2010-05-21T07:04:44+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=af0e502b-155a-47f9-a08e-365b39f4fb12" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/UP7GuCkBIIc/Workaround-for-VSTO-bug-Content-control-Exiting-event-handler.aspx" />
    <author>
      <name>Janko</name>
    </author>
    <summary type="html">&lt;p&gt;If you have ever worked on some Word add-in where you use content controls, you maybe have encountered problems for which you have no explanations. This post is about one of the known VSTO issues and offers a workaround for it.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We were working on Word add-in that uses content controls. Also we needed to process data on entering and exiting a content control. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Good thing is that VSTO offers events &lt;b&gt;Entering&lt;/b&gt; and &lt;b&gt;Exiting&lt;/b&gt;.&lt;b&gt; &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Bad thing is that &lt;b&gt;Exiting&lt;/b&gt; event has a bug. If you are doing some &amp;quot;simple&amp;quot; process in &lt;b&gt;Exiting&lt;/b&gt; event handler it could work fine, but you never know what will happen. Using this event could produce very strange problems, problems which look like they should not have any connections with the event.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Several strange problems have occurred for which we were unable to find a solution. So we created different POC projects to reproduce and isolate the bugs and posted them on the Microsoft forum. Shortly the issues were confirmed - one of them as a new VSTO bug (&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/556456/programatically-deselecting-a-content-control-results-in-a-com-exception?wa=wsignin1.0" target="_blank"&gt;https://connect.microsoft.com/VisualStudio/feedback/details/556456/programatically-deselecting-a-content-control-results-in-a-com-exception?wa=wsignin1.0&lt;/a&gt;) and another got recognized as a notorious VSTO bug. After using proposed workaround for notorious bug, both bugs were resolved.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;The notorious&lt;/u&gt; &lt;u&gt;problem manifests itself in following way:&lt;/u&gt;&lt;/h4&gt;  &lt;p&gt;In the document there are two building block content controls: &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&amp;#160;&lt;b&gt;POCControl1&lt;/b&gt; and &lt;/li&gt;    &lt;li&gt;&lt;b&gt;&amp;#160;&lt;/b&gt;&lt;b&gt;POCControl2&lt;/b&gt;&lt;b&gt;&lt;/b&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;On the document startup we are adding &lt;b&gt;Entering&lt;/b&gt; and &lt;b&gt;Exiting&lt;/b&gt; event handlers to these controls. &lt;/p&gt;  &lt;p&gt;-On &lt;b&gt;Entering&lt;/b&gt; the control &lt;b&gt;TrackChanges&lt;/b&gt; is set to TRUE and old value is remembered.&lt;/p&gt;  &lt;p&gt;-On &lt;b&gt;Exiting&lt;/b&gt; all changes are confirmed and &lt;b&gt;TrackChanges&lt;/b&gt; is returned to the previous version.&lt;/p&gt;  &lt;p&gt;Problem occurs in following scenario:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Select &lt;b&gt;POCControl1&lt;/b&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;&lt;i&gt;Entering&lt;/i&gt;&lt;/b&gt;&lt;i&gt; event occurs.&lt;/i&gt;&lt;/li&gt;    &lt;li&gt;Unselect &lt;b&gt;POCControl1&lt;/b&gt;.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;&lt;i&gt;Exiting&lt;/i&gt;&lt;/b&gt;&lt;i&gt; event occurs. &lt;/i&gt;&lt;/li&gt; PROBLEM: on line&lt;i&gt;      &lt;br /&gt;&lt;/i&gt;Me.TrackRevisions = Me._oldTrackRevisionsStatus     &lt;br /&gt;&lt;b&gt;&lt;i&gt;Entering&lt;/i&gt;&lt;/b&gt;&lt;i&gt; event for &lt;b&gt;POCControl1&lt;/b&gt; occurs (which should not happen). After it finishes, &lt;b&gt;Exiting&lt;/b&gt; event continues to run from the specified line&lt;/i&gt;.&lt;/ol&gt;  &lt;p&gt;Even stranger behavior occurs when selecting &lt;b&gt;POCControl1&lt;/b&gt; and then selecting &lt;b&gt;POCControl2&lt;/b&gt;. Here is the whole POC code:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; ThisDocument

    &lt;span class="kwrd"&gt;Private&lt;/span&gt; _oldTrackRevisionsStatus &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;

    &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; ThisDocument_Startup(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt;, _&lt;/pre&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;                                     &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; System.EventArgs) &lt;span class="kwrd"&gt;Handles&lt;/span&gt; &lt;span class="kwrd"&gt;Me&lt;/span&gt;.Startup
        &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; POCControl1.Entering, &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; TextItemSelected
        &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; POCControl2.Entering, &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; TextItemSelected
        &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; POCControl1.Exiting, &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; TextItemUnselected
        &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; POCControl2.Exiting, &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; TextItemUnselected

        POCControl1.Tag = &lt;span class="str"&gt;&amp;quot;UPPER control&amp;quot;&lt;/span&gt;
        POCControl2.Tag = &lt;span class="str"&gt;&amp;quot;LOWER control&amp;quot;&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; TextItemSelected(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; BuildingBlockGalleryContentControl, _&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;                                &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; ContentControlEnteringEventArgs)
        MsgBox(&lt;span class="str"&gt;&amp;quot;Select &amp;quot;&lt;/span&gt; &amp;amp; sender.Tag &amp;amp; &lt;span class="str"&gt;&amp;quot; beggining&amp;quot;&lt;/span&gt;)

        &lt;span class="rem"&gt;' Set track changes:&lt;/span&gt;
        _oldTrackRevisionsStatus = &lt;span class="kwrd"&gt;Me&lt;/span&gt;.TrackRevisions
        &lt;span class="kwrd"&gt;Me&lt;/span&gt;.TrackRevisions = &lt;span class="kwrd"&gt;True&lt;/span&gt;

        MsgBox(&lt;span class="str"&gt;&amp;quot;Select &amp;quot;&lt;/span&gt; &amp;amp; sender.Tag &amp;amp; &lt;span class="str"&gt;&amp;quot; ending&amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; TextItemUnselected(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; BuildingBlockGalleryContentControl, _
                           &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; cevent &lt;span class="kwrd"&gt;As&lt;/span&gt; Tools.Word.ContentControlExitingEventArgs)
        MsgBox(&lt;span class="str"&gt;&amp;quot;Unselect &amp;quot;&lt;/span&gt; &amp;amp; sender.Tag &amp;amp; &lt;span class="str"&gt;&amp;quot; beggining&amp;quot;&lt;/span&gt;)

        &lt;span class="kwrd"&gt;If&lt;/span&gt; sender.Range.Revisions.Count &amp;gt; 0 &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            sender.Range.Revisions.AcceptAll()
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

        &lt;span class="kwrd"&gt;Me&lt;/span&gt;.TrackRevisions = &lt;span class="kwrd"&gt;Me&lt;/span&gt;._oldTrackRevisionsStatus

        MsgBox(&lt;span class="str"&gt;&amp;quot;Unselect &amp;quot;&lt;/span&gt; &amp;amp; sender.Tag &amp;amp; &lt;span class="str"&gt;&amp;quot; ending&amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;font size="3"&gt;Proposed solution&lt;/font&gt;:&lt;/h4&gt;

&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Do not use &lt;b&gt;Exiting&lt;/b&gt; event at all. For example, use &lt;b&gt;Application.WindowSelectionChange&lt;/b&gt; event instead, which we did. This event is triggered on every selection change in the active document window, whenever it is manually or programmatically caused. In its handler we are tracking &amp;quot;exiting&amp;quot; from the control. &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So we removed &lt;b&gt;Exiting&lt;/b&gt; event handler and related code from our POC project and added &lt;b&gt;WindowSelectionChange&lt;/b&gt; event handler: &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; _oldTrackRevisionsStatus &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;
    &lt;span class="kwrd"&gt;Private&lt;/span&gt; selectedControl &lt;span class="kwrd"&gt;As&lt;/span&gt; Tools.Word.BuildingBlockGalleryContentControl

    &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; ThisDocument_Startup(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt;, _&lt;/pre&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;                                     &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; System.EventArgs) &lt;span class="kwrd"&gt;Handles&lt;/span&gt; &lt;span class="kwrd"&gt;Me&lt;/span&gt;.Startup
        &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; POCControl1.Entering, &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; TextItemSelected
        &lt;span class="kwrd"&gt;AddHandler&lt;/span&gt; POCControl2.Entering, &lt;span class="kwrd"&gt;AddressOf&lt;/span&gt; TextItemSelected
        
        POCControl1.Tag = &lt;span class="str"&gt;&amp;quot;UPPERControl&amp;quot;&lt;/span&gt;
        POCControl2.Tag = &lt;span class="str"&gt;&amp;quot;LOWERControl&amp;quot;&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; TextItemSelected(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; BuildingBlockGalleryContentControl, _&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;                                &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; ContentControlEnteringEventArgs)
        MsgBox(&lt;span class="str"&gt;&amp;quot;Select &amp;quot;&lt;/span&gt; &amp;amp; sender.Tag &amp;amp; &lt;span class="str"&gt;&amp;quot; beggining&amp;quot;&lt;/span&gt;)

        selectedControl = sender

        &lt;span class="rem"&gt;' Set track changes:&lt;/span&gt;
        _oldTrackRevisionsStatus = &lt;span class="kwrd"&gt;Me&lt;/span&gt;.TrackRevisions
        &lt;span class="kwrd"&gt;Me&lt;/span&gt;.TrackRevisions = &lt;span class="kwrd"&gt;True&lt;/span&gt;

        MsgBox(&lt;span class="str"&gt;&amp;quot;Select &amp;quot;&lt;/span&gt; &amp;amp; sender.Tag &amp;amp; &lt;span class="str"&gt;&amp;quot; ending&amp;quot;&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; WindowSelectionChange_Handler(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sel &lt;span class="kwrd"&gt;As&lt;/span&gt; Interop.Word.Selection) _&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;                                      &lt;span class="kwrd"&gt;Handles&lt;/span&gt; ThisApplication.WindowSelectionChange
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; control &lt;span class="kwrd"&gt;As&lt;/span&gt; Interop.Word.ContentControl = sel.Range.ParentContentControl
        &lt;span class="kwrd"&gt;If&lt;/span&gt; selectedControl IsNot &lt;span class="kwrd"&gt;Nothing&lt;/span&gt; _&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;         &lt;span class="kwrd"&gt;AndAlso&lt;/span&gt; (control &lt;span class="kwrd"&gt;Is&lt;/span&gt; &lt;span class="kwrd"&gt;Nothing&lt;/span&gt; &lt;span class="kwrd"&gt;OrElse&lt;/span&gt; control.Tag &amp;lt;&amp;gt; selectedControl.Tag) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            MsgBox(&lt;span class="str"&gt;&amp;quot;Unselect &amp;quot;&lt;/span&gt; &amp;amp; selectedControl.Tag &amp;amp; &lt;span class="str"&gt;&amp;quot; beggining&amp;quot;&lt;/span&gt;)

            &lt;span class="kwrd"&gt;If&lt;/span&gt; selectedControl.Range.Revisions.Count &amp;gt; 0 &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                selectedControl.Range.Revisions.AcceptAll()
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

            &lt;span class="kwrd"&gt;Me&lt;/span&gt;.TrackRevisions = &lt;span class="kwrd"&gt;Me&lt;/span&gt;._oldTrackRevisionsStatus

            selectedControl = &lt;span class="kwrd"&gt;Nothing&lt;/span&gt;

            MsgBox(&lt;span class="str"&gt;&amp;quot;Unselect ending&amp;quot;&lt;/span&gt;)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;If you have issues with content controls and you are using &lt;b&gt;Exiting&lt;/b&gt; event, it is possible that it is the root of your problems. Use &lt;b&gt;WindowSelectionChange&lt;/b&gt; event and adapt its handler for your own code. It helped us and might potentially help you get rid of some annoying bugs and unwanted behavior.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/UP7GuCkBIIc" height="1" width="1"/&gt;</summary>
    <published>2010-05-21T07:04:44+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/Workaround-for-VSTO-bug-Content-control-Exiting-event-handler.aspx#comment" />
    <category term="ICF.Labs" />
    <category term=".NET" />
    <category term="VSTO" />
    <dc:publisher>Janko</dc:publisher>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=af0e502b-155a-47f9-a08e-365b39f4fb12</pingback:target>
    <slash:comments>68</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=af0e502b-155a-47f9-a08e-365b39f4fb12</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/Workaround-for-VSTO-bug-Content-control-Exiting-event-handler.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=af0e502b-155a-47f9-a08e-365b39f4fb12</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/Workaround-for-VSTO-bug-Content-control-Exiting-event-handler.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/Dynamically-adding-ASPNET-validators-and-ASPNET-ajax-validation-callout-extenders-using-Javascript.aspx</id>
    <title>Dynamically adding ASP.NET validators and ASP.NET ajax validation callout extenders using Javascript</title>
    <updated>2010-05-13T06:33:00+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=673d5ba5-ce82-45c0-a72e-8d4256557eea" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/n44AEsOu6tM/Dynamically-adding-ASPNET-validators-and-ASPNET-ajax-validation-callout-extenders-using-Javascript.aspx" />
    <author>
      <name>Lacio</name>
    </author>
    <summary type="html">&lt;p&gt;Have you ever encountered a problem where you generated some content dynamically without the help of the server and server side code, but still needed to perform some basic validation on those contents? &lt;/p&gt;  &lt;p&gt;That is exactly what this post deals with – validating content which is taken from dynamically generated input fields and adding the validation callout extender to it.&amp;#160; &lt;/p&gt;  &lt;p&gt;Since I did not find any suitable solutions online, I decided to do it myself. Turned out the solution is not so hard at all, and after a small analysis on the page source of pages with regular validation, I got an idea on how to do it.&lt;/p&gt;  &lt;p&gt;The first thing to notice is that after the aspx page is parsed, the output of a validator control (of any type) is a SPAN tag. Sort of. The tag has some unconventional attributes, off course depending on the type of the validator used, but we will get to that later. Besides this, a reference to the span is kept in an array called Page_Validators, which is an array consisting of all the validators present on the page.&lt;/p&gt;  &lt;p&gt;So let’s go step by step.&lt;/p&gt;  &lt;h6&gt;&lt;/h6&gt;  &lt;p&gt;First create the span tag and place it in the DOM where you would place the validator control. Lets say we have an input field and we place a RequiredFieldValidator next to it, like in the code below:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;               // Get the table:&lt;/span&gt;
                var tblEditItems = $get(&lt;span class="str"&gt;'tblEditItems'&lt;/span&gt;);
                &lt;span class="rem"&gt;// Get the number of rows currently in the table:&lt;/span&gt;
                var rowsCount = tblEditItems.rows.length;
                &lt;span class="rem"&gt;// Insert a new row at the end of the table:&lt;/span&gt;
                var row = tblEditItems.insertRow(rowsCount);

                &lt;span class="rem"&gt;// Insert a table cell:&lt;/span&gt;
                var cellName = row.insertCell(0);
                &lt;span class="rem"&gt;// Create an input field for the name:&lt;/span&gt;
                var elName = document.createElement(&lt;span class="str"&gt;'input'&lt;/span&gt;);
                elName.type = &lt;span class="str"&gt;'text'&lt;/span&gt;;
                elName.size = 10;
                elName.id = &lt;span class="str"&gt;'txtProductName'&lt;/span&gt; + globalControlCounter;
                cellName.appendChild(elName);

                &lt;span class="rem"&gt;// Add the span that will represent the validotor&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;                // (in this case the required field validator):&lt;/span&gt;
                var elNameValidator = document.createElement(&lt;span class="str"&gt;'span'&lt;/span&gt;);
                elNameValidator.style.color = &lt;span class="str"&gt;&amp;quot;Red&amp;quot;&lt;/span&gt;;
                elNameValidator.style.display = &lt;span class="str"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;;
                elNameValidator.id = elName.id + &lt;span class="str"&gt;&amp;quot;Validator&amp;quot;&lt;/span&gt;;
                elNameValidator.controltovalidate = elName.id;
                elNameValidator.errormessage = &lt;span class="str"&gt;&amp;quot;&amp;lt;b&amp;gt;Field is incorrect&amp;lt;/b&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="str"&gt;                                     &amp;lt;br /&amp;gt; &amp;lt;span&amp;gt;Name is a required field.&amp;lt;/span&amp;gt;&amp;quot;&lt;/span&gt;;
                elNameValidator.validationGroup = &lt;span class="str"&gt;&amp;quot;EditItems&amp;quot;&lt;/span&gt;;
                elNameValidator.initialvalue = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
                elNameValidator.evaluationfunction =&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;                                              RequiredFieldValidatorEvaluateIsValid;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The next step is to add the validator to the array of existing validators:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;                &lt;span class="rem"&gt;// Push the new validator inside the page validators array:&lt;/span&gt;
                Page_Validators.push(elNameValidator);&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;After this is done, we can add the validator callout extender control, that will add some nice pop out effects displaying the error message itself:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;                &lt;span class="rem"&gt;// Now lets bind the validator callout that will popup&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;                // up when the field is not valid:&lt;/span&gt;
                $create(AjaxControlToolkit.ValidatorCalloutBehavior, {
                    &lt;span class="str"&gt;&amp;quot;closeImageUrl&amp;quot;&lt;/span&gt;: &lt;span class="str"&gt;&amp;quot;/image/close.png&amp;quot;&lt;/span&gt;,
                    &lt;span class="str"&gt;&amp;quot;highlightCssClass&amp;quot;&lt;/span&gt;: &lt;span class="str"&gt;&amp;quot;highlight&amp;quot;&lt;/span&gt;,
                    &lt;span class="str"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;: elNameValidator.id + &lt;span class="str"&gt;&amp;quot;ValidatorCalloutExtender&amp;quot;&lt;/span&gt;,
                    &lt;span class="str"&gt;&amp;quot;warningIconImageUrl&amp;quot;&lt;/span&gt;: &lt;span class="str"&gt;&amp;quot;../images/attention.png&amp;quot;&lt;/span&gt;
                }, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;, $get(elNameValidator.id));&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The last step that needs to be taken and is essential for this to work is to add some dummy validator and dummy validator callout extender to the page. This is needed, as otherwise the necessary javascript libraries will not be included on the page (either this, or including the libraries by hand, whichever solution you prefer).&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Now, the triggering of the validators is up to you – I used triggering when the user clicks some submit action. Since the action does not cause a postback, I needed some client side validation check. If you have the same problem, you can check out this simple solution located on &lt;a href="http://www.icodefactory.com/lab/post/How-to-trigger-an-ASPNET-validator-from-JavaScript.aspx"&gt;this post.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;As you can see, it is really easy to create the validation and add the validator callout extenders, with just a bit of knowledge in javascript. I recommend experimenting with different types of validators, as they all attach different attributes to the DOM element. If you have any questions or suggestions, feel free to post them to the comments section, I will try my best to help.&lt;/p&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/n44AEsOu6tM" height="1" width="1"/&gt;</summary>
    <published>2010-05-13T06:33:00+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/Dynamically-adding-ASPNET-validators-and-ASPNET-ajax-validation-callout-extenders-using-Javascript.aspx#comment" />
    <category term=".NET" />
    <category term="ASP.NET" />
    <category term="ICF.Labs" />
    <dc:publisher>Lacio</dc:publisher>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=673d5ba5-ce82-45c0-a72e-8d4256557eea</pingback:target>
    <slash:comments>138</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=673d5ba5-ce82-45c0-a72e-8d4256557eea</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/Dynamically-adding-ASPNET-validators-and-ASPNET-ajax-validation-callout-extenders-using-Javascript.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=673d5ba5-ce82-45c0-a72e-8d4256557eea</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/Dynamically-adding-ASPNET-validators-and-ASPNET-ajax-validation-callout-extenders-using-Javascript.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/ASPNET-AJAX-40-Templates-Simple-Demo-Step-by-Step.aspx</id>
    <title>ASP.NET AJAX 4.0 Templates Simple Demo - Step by Step</title>
    <updated>2009-11-27T08:59:00+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=099a9a31-164b-4135-a4ce-9c26e30fb764" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/oBmq89WYhAk/ASPNET-AJAX-40-Templates-Simple-Demo-Step-by-Step.aspx" />
    <author>
      <name>Sergio</name>
    </author>
    <summary type="html">&lt;p&gt;This quick step by step tutorial is made with Visual Studio 2010 beta2    &lt;br /&gt;and ASP.NET AJAX 4.0 Preview 6.     &lt;br /&gt;It is possible that some properties and/or methods will be changed in future versions, but so far this is the way to use client side templates in ASP.NET AJAX 4.0.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;Downloads&lt;/h2&gt;  &lt;p&gt;First you should download appropriate software:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Microsoft .NET Framework 4.0 &lt;/li&gt;    &lt;li&gt;Microsoft Visual Studio 2010 &lt;/li&gt;    &lt;li&gt;ASP.NET Ajax Library &lt;/li&gt; &lt;/ol&gt;  &lt;h2&gt;Project&lt;/h2&gt;  &lt;p&gt;For your first project you should use web site or web project visual studio templates, create new project and add appropriate scripts to a project.&lt;/p&gt;  &lt;p&gt;For this example I’ve created a new web site and added all the AJAX scripts we need to a folder named “MicrosoftAJAX” (look at the picture).&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/ASP.NETAJAX4.0TemplatesStepbyStep/08255D9E/WebSiteProjectFiles.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WebSiteProjectFiles" border="0" alt="WebSiteProjectFiles" src="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/ASP.NETAJAX4.0TemplatesStepbyStep/09A679B2/WebSiteProjectFiles_thumb.jpg" width="219" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Also I have created a simple demo xml web service to be used from client side to read data for our template.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&amp;lt;%@ WebService Language=&lt;span class="str"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt; Class=&lt;span class="str"&gt;&amp;quot;DemoService&amp;quot;&lt;/span&gt; %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Services;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Services.Protocols;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;[WebService(Namespace = &lt;span class="str"&gt;&amp;quot;http://icodefactory.com/&amp;quot;&lt;/span&gt;, &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;   Description=&lt;span class="str"&gt;&amp;quot;Demo web service used by client side templates&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&lt;span class="rem"&gt;// To allow this Web Service to be called from script, &lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&lt;span class="rem"&gt;// using ASP.NET AJAX, uncomment the following line. &lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;[System.Web.Script.Services.ScriptService]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DemoService  : System.Web.Services.WebService {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;    [WebMethod(Description=&lt;span class="str"&gt;&amp;quot;Returns Demo Contacts data&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Contact[] GetContacts() {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;        Contact[] contacts = &lt;span class="kwrd"&gt;new&lt;/span&gt; Contact[3] {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; Contact(){ Id=1, Name = &lt;span class="str"&gt;&amp;quot;John&amp;quot;&lt;/span&gt;, Lastname=&lt;span class="str"&gt;&amp;quot;Doe&amp;quot;&lt;/span&gt; },&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; Contact(){ Id=2, Name = &lt;span class="str"&gt;&amp;quot;Joan&amp;quot;&lt;/span&gt;, Lastname=&lt;span class="str"&gt;&amp;quot;Smith&amp;quot;&lt;/span&gt; },&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; Contact(){ Id=3, Name = &lt;span class="str"&gt;&amp;quot;Brad&amp;quot;&lt;/span&gt;, Lastname=&lt;span class="str"&gt;&amp;quot;Forbs&amp;quot;&lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;        };&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; contacts;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;    &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Pay attention that you have to set the ScriptService attribute so your web service can be used from JavaScript.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Finally we have to add some simple html (yes, pure html) file and import appropriate scripts:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;MicrosoftAjax.js &lt;/li&gt;

  &lt;li&gt;MicrosoftAjaxTemplates.js &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;for AJAX client side libraries and&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;DemoService.asmx/jsdebug &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;for access to the xml web service.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&amp;lt;script src=&lt;span class="str"&gt;&amp;quot;MicrosoftAJAX/MicrosoftAjax.debug.js&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;        type=&lt;span class="str"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&amp;lt;script src=&lt;span class="str"&gt;&amp;quot;MicrosoftAJAX/MicrosoftAjaxTemplates.debug.js&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        type=&lt;span class="str"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;lt;script src=&lt;span class="str"&gt;&amp;quot;DemoService.asmx/jsdebug&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        type=&lt;span class="str"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;We also need some styling on the page. Class ‘sys-template’ is used to hide empty table before data is bound from the service by using AJAX DataView client side control.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&amp;lt;style type=&lt;span class="str"&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;        &lt;span class="rem"&gt;/*Used to hide empty table*/&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        .sys-template&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;            display: none;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="rem"&gt;/* Style of table that shows data*/&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        .table_style&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            background-color: Olive;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;            padding: 5px 5px 5px 5px;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    &amp;lt;/style&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Now, time for JavaScript that should load the data from the xml web service, fill the DataView object and bind the data to the html template.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;script type=&lt;span class="str"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt;
        &lt;span class="rem"&gt;// ASP.NET Ajax client side control - DataView&lt;/span&gt;
        &lt;span class="kwrd"&gt;var&lt;/span&gt; contactsView;
        
        &lt;span class="rem"&gt;// Triggers on page load&lt;/span&gt;
        &lt;span class="kwrd"&gt;function&lt;/span&gt; pageLoad() {
            &lt;span class="rem"&gt;// Create Contacts DataView&lt;/span&gt;
            contactsView = 
                      $create(Sys.UI.DataView, {}, {}, {}, $get(&lt;span class="str"&gt;&amp;quot;contactsBody&amp;quot;&lt;/span&gt;));

            &lt;span class="rem"&gt;// Load Contacts from web service&lt;/span&gt;
            DemoService.GetContacts(ContactsLoaded);
        }
        
        &lt;span class="kwrd"&gt;function&lt;/span&gt; ContactsLoaded(contactsData) {
            &lt;span class="rem"&gt;// Display data in Contacts DataView&lt;/span&gt;
            contactsView.set_data(contactsData);
        }
    &amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The pageLoad function creates the DataView client side object and calls the xml web service to populate the object with data.&lt;/p&gt;

&lt;p&gt;On successful service call the data is bound to the html with a simple call to the set_data() function.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This is how your template should look:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;table&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;table_style&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;border&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;cellpadding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;4&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;cellspacing&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;4&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;thead&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;                    Name&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;                    Lastname&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;thead&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        &lt;span class="rem"&gt;&amp;lt;!-- tbody tag id is used to identify tag in DOM that are going to be&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;&lt;span class="rem"&gt;             used by the DataView. Class is set to 'sys-template' in order to&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&lt;span class="rem"&gt;             hide empty table --&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tbody&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;contactsBody&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;sys-template&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;                    {{ Name }}&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;                    {{ Lastname }}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;tbody&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;table&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;lt;tbody&amp;gt; tag is used to become a template for the data in the DataView object.&lt;/p&gt;

&lt;p&gt;DataView will change HTML with appropriate tags and generate table rows for every data row from the xml web service method call.&lt;/p&gt;

&lt;p&gt;{{ Name }} and {{ Lastname }} parts will be replaced with actual data.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;At the end you have your data.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/ASP.NETAJAX4.0TemplatesStepbyStep/67DAA120/DemoSite_Result.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DemoSite_Result" border="0" alt="DemoSite_Result" src="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/ASP.NETAJAX4.0TemplatesStepbyStep/258788DD/DemoSite_Result_thumb.jpg" width="244" height="124" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Hope this will help you start with the new templates. Web development is moving to client side and everyone should embrace the client side because of its many benefits, like responsiveness, bandwidth and UI patterns.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Demo Solution may be downloaded from our &lt;a title="public download" href="http://www.icodefactory.com/download.aspx" target="_blank"&gt;public download section.&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/oBmq89WYhAk" height="1" width="1"/&gt;</summary>
    <published>2009-11-27T08:59:00+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/ASPNET-AJAX-40-Templates-Simple-Demo-Step-by-Step.aspx#comment" />
    <category term="ASP.NET" />
    <dc:publisher>Sergio</dc:publisher>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=099a9a31-164b-4135-a4ce-9c26e30fb764</pingback:target>
    <slash:comments>87</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=099a9a31-164b-4135-a4ce-9c26e30fb764</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/ASPNET-AJAX-40-Templates-Simple-Demo-Step-by-Step.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=099a9a31-164b-4135-a4ce-9c26e30fb764</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/ASPNET-AJAX-40-Templates-Simple-Demo-Step-by-Step.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/How-to-trigger-an-ASPNET-validator-from-JavaScript.aspx</id>
    <title>How to trigger an ASP.NET validator from JavaScript?</title>
    <updated>2009-10-07T09:40:00+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=eb031cf5-67ca-40e5-8b24-1f1128b64293" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/3KAIESaE_W0/How-to-trigger-an-ASPNET-validator-from-JavaScript.aspx" />
    <author>
      <name>Lacio</name>
    </author>
    <summary type="html">&lt;p&gt;
Have you ever been in a situation when You were not able to perform server side validation and were not able to trigger the validators in the standardized way. By this I mean that you had a button that was doing a submit, but without causing any postback, and doing it all through JavaScript. In my case, I had a pagemethod that was doing a save for some entity we needed. So because of the nature of this operation, I needed to do a validation &amp;ndash; and off course I used different kinds of validators &amp;ndash; from range to required field and custom validators. So what is the problem then &amp;ndash; the problem is that the JavaScript hides the form for the insert and the validation messages get lost, and along the way either a false insert or an exception is thrown &amp;ndash; some fields might even be potential security breaches without proper validation. So I wandered around trying to find a way to perform regular validation, the way it is supposed to be done. I found a nice, elegant way to do it and even make it reusable on all the pages that need JavaScript validation and have the same problems as stated above.
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
An example of how validation works:
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
&lt;a href="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/Howtotriggera.NETvalidatorfromJavaScript/345BAF73/blogpic.jpg"&gt;&lt;img style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto" src="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/Howtotriggera.NETvalidatorfromJavaScript/3668886F/blogpic_thumb.jpg" border="0" alt="blogpic" title="blogpic" width="582" height="546" /&gt;&lt;/a&gt; 
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
So the solution is to write a small JavaScript function that will invoke all the validators that belong to a certain group. Below is the JavaScript function.
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
function ValidateEntry(validationGroup) {
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; var isValidEntry = true;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; if (typeof (Page_Validators) != &amp;#39;undefined&amp;#39;) {
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (var i = 0; i &amp;lt; Page_Validators.length; i++) {
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (Page_Validators[i].validationGroup == validationGroup) {
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // call validator function
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var func = Page_Validators[i].evaluationfunction;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Page_Validators[i].isvalid = func(Page_Validators[i]);
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!Page_Validators[i].isvalid) {
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; isValidEntry = false;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Page_Validators[i].style.visibility = &amp;#39;&amp;#39;;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; }
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; return isValidEntry
&lt;/p&gt;
  
&lt;p&gt;
}
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
So how does this work? The function returns a boolean value that suggests whether the validation is correct. The function goes through all the page validators, and selects the ones which belong to the specified validation group &amp;ndash; this way we ensure only validators needed to be invoked are actually checked. 
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
Later, we just call the ValidateEntry JavaScript function before calling the method that does the persisting &amp;ndash; in my example, before calling a pagemethod that calls some server side method that does an insert in the db. The example is below:
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
First we have the controls that have the validators on them:
&lt;/p&gt;
  
&lt;p&gt;
&amp;lt;td&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; &amp;lt;asp:TextBox MaxLength=&amp;quot;50&amp;quot; ID=&amp;quot;txtNewName&amp;quot; runat=&amp;quot;server&amp;quot;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Width=&amp;quot;495px&amp;quot; ValidationGroup=&amp;quot;NewEntityValidationGroup&amp;quot;&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; &amp;lt;/asp:TextBox&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;lt;/td&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;lt;td&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; &amp;lt;asp:RequiredFieldValidator ID=&amp;quot;valNewName&amp;quot; Text=&amp;quot;*&amp;quot; ValidationGroup=&amp;quot;NewEntityValidationGroup&amp;quot; runat=&amp;quot;server&amp;quot; ControlToValidate=&amp;quot;txtNewName&amp;quot;&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; &amp;lt;/asp:RequiredFieldValidator&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;lt;/td&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;lt;td&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; &amp;lt;asp:TextBox ID=&amp;quot;txtNewDescription&amp;quot; TextMode=&amp;quot;multiLine&amp;quot; runat=&amp;quot;server&amp;quot; Height=&amp;quot;100px&amp;quot; Width=&amp;quot;495px&amp;quot; ValidationGroup=&amp;quot;NewEntityValidationGroup&amp;quot;&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; &amp;lt;/asp:TextBox&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;lt;/td&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;lt;td&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; &amp;lt;asp:RequiredFieldValidator ID=&amp;quot;valNewDescription&amp;quot; Text=&amp;quot;*&amp;quot; ValidationGroup=&amp;quot;NewEntityValidationGroup&amp;quot; runat=&amp;quot;server&amp;quot; ControlToValidate=&amp;quot;txtNewDescription&amp;quot;&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; &amp;lt;/asp:RequiredFieldValidator&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
&amp;lt;/td&amp;gt;
&lt;/p&gt;
  
&lt;p&gt;
Then we have the pagemethod call with the call to the validation function (ValidateEntry):
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
function AddNewEntity() {
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; if (ValidateEntry(&amp;quot;NewEntityValidationGroup&amp;quot;)) {
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var entityName = $get(&amp;#39;&amp;lt;%=txtNewName.ClientID %&amp;gt;&amp;#39;);
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var entityDescription=get(&amp;#39;&amp;lt;%=txtNewDescription.ClientID %&amp;gt;&amp;#39;);
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PageMethods.AddEntity(entityName.value, entityDescription.value, AddEntitySuccess, OnFailure);
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp; }
&lt;/p&gt;
  
&lt;p&gt;
}
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
Lets analyze the function above &amp;ndash; before we do any processing, we check all the validators, and only if the function returns &lt;strong&gt;true&lt;/strong&gt;, we continue with the field value retrieval and call the pagemethod.
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
The best practice to use this type of validation would be to extract it to a new file and include the JavaScript file wherever it is needed.
&lt;/p&gt;
  
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
  
&lt;p&gt;
If you want to incorporate this into your solution, feel free to go ahead and use the JavaScript function above, it is easy to integrate &amp;ndash;just copy it to your solution, either to the page itself or to a JavaScript file and then just call it.
&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/3KAIESaE_W0" height="1" width="1"/&gt;</summary>
    <published>2009-10-07T09:40:00+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/How-to-trigger-an-ASPNET-validator-from-JavaScript.aspx#comment" />
    <dc:publisher>Lacio</dc:publisher>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=eb031cf5-67ca-40e5-8b24-1f1128b64293</pingback:target>
    <slash:comments>50</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=eb031cf5-67ca-40e5-8b24-1f1128b64293</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/How-to-trigger-an-ASPNET-validator-from-JavaScript.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=eb031cf5-67ca-40e5-8b24-1f1128b64293</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/How-to-trigger-an-ASPNET-validator-from-JavaScript.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/FCKEditor-with-ASPNET-Fix-The-server-did-not-send-back-a-proper-XML-response-error.aspx</id>
    <title>FCKEditor with ASP.NET - Fix “The server did not send back a proper XML response error”.</title>
    <updated>2009-07-07T15:47:00+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=20d0349b-1189-443e-b00d-a28b5a91f980" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/isWRnnIlQtA/FCKEditor-with-ASPNET-Fix-The-server-did-not-send-back-a-proper-XML-response-error.aspx" />
    <author>
      <name>Sergio</name>
    </author>
    <summary type="html">&lt;p&gt;
I like FCKEditor. Our company is using it on several projects, and it mainly works fine, it has a number of different functionalities and it integrates well. 
&lt;/p&gt;
&lt;p&gt;
Recently we integrated FCKEditor with an asp.net 3.5 web application. We wanted to allow the client to update some contents on the web site and upload/manipulate images, but we faced a strange exception that stated: 
&lt;/p&gt;
&lt;h2&gt;The server didn&amp;rsquo;t send back a proper XML response. Please contact your system administrator. &lt;br /&gt;
XML request error: Ok (200)&lt;/h2&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/FCKEditorwithASP.NETFixTheserverdidntse/7AF1CF7F/xmlrequesterror_image1.jpg"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px; border: 0px" src="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/FCKEditorwithASP.NETFixTheserverdidntse/68D56625/xmlrequesterror_image1_thumb.jpg" border="0" alt="xmlrequesterror_image1" title="xmlrequesterror_image1" width="240" height="180" align="right" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Response text looked scrambled and messy. 
&lt;/p&gt;
&lt;p&gt;
Our first reaction was to search for the same bug on net, but after a few days I did not find anything barely useful! 
&lt;/p&gt;
&lt;p&gt;
That&amp;rsquo;s about when I realized I&amp;rsquo;ll have to investigate it by myself. 
&lt;/p&gt;
&lt;p&gt;
First of all I supposed I should blame some response mime type or format, so I dived into the FCKEditor project source code and found a class named XmlResponseHandler. 
&lt;/p&gt;
&lt;p&gt;
This class is used to clear the response object, set the content encoding and content type. 
&lt;/p&gt;
&lt;p&gt;
It all looked well. It was time to put some break points and investigate what is going on there. 
&lt;/p&gt;
&lt;p&gt;
I monitored two methods: SetupResponse and SendResponse. 
&lt;/p&gt;
&lt;p&gt;
private static void SetupResponse( HttpResponse response ) 
&lt;/p&gt;
&lt;p&gt;
{ 
&lt;/p&gt;
&lt;p&gt;
// Cleans the response buffer. 
&lt;/p&gt;
&lt;p&gt;
response.ClearHeaders(); 
&lt;/p&gt;
&lt;p&gt;
response.Clear(); 
&lt;/p&gt;
&lt;p&gt;
// Prevent the browser from caching the result. 
&lt;/p&gt;
&lt;p&gt;
response.CacheControl = &amp;quot;no-cache&amp;quot;; 
&lt;/p&gt;
&lt;p&gt;
// Set the response format. 
&lt;/p&gt;
&lt;p&gt;
response.ContentEncoding = System.Text.UTF8Encoding.UTF8; 
&lt;/p&gt;
&lt;p&gt;
response.Charset = &amp;quot;utf-8&amp;quot;; 
&lt;/p&gt;
&lt;p&gt;
response.ContentType = &amp;quot;text/xml&amp;quot;; 
&lt;/p&gt;
&lt;p&gt;
} 
&lt;/p&gt;
&lt;p&gt;
public void SendResponse() 
&lt;/p&gt;
&lt;p&gt;
{ 
&lt;/p&gt;
&lt;p&gt;
SetupResponse(); 
&lt;/p&gt;
&lt;p&gt;
Response.Write( Xml.OuterXml ); 
&lt;/p&gt;
&lt;p&gt;
Response.End(); 
&lt;/p&gt;
&lt;p&gt;
} 
&lt;/p&gt;
&lt;p&gt;
Let&amp;rsquo;s put some break points and check what is going on while looking for the xml response from the server. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/FCKEditorwithASP.NETFixTheserverdidntse/6A760C2C/code_with_break_points_image2.jpg"&gt;&lt;img style="display: inline; border: 0px" src="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/FCKEditorwithASP.NETFixTheserverdidntse/14D2177D/code_with_break_points_image2_thumb.jpg" border="0" alt="code_with_break_points_image2" title="code_with_break_points_image2" width="244" height="178" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
My attention was drawn to data. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/FCKEditorwithASP.NETFixTheserverdidntse/3EF19F98/xmldata_image3.jpg"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px; border: 0px" src="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/FCKEditorwithASP.NETFixTheserverdidntse/691127B3/xmldata_image3_thumb.jpg" border="0" alt="xmldata_image3" title="xmldata_image3" width="244" height="81" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
SendResponse method has a well formed xml. Let&amp;rsquo;s go further through the code. 
&lt;/p&gt;
&lt;p&gt;
Oops! 
&lt;/p&gt;
&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;
&lt;h2&gt;&lt;strong&gt;The server didn&amp;rsquo;t send back a proper XML response. Please contact your system administrator.&lt;/strong&gt;&lt;/h2&gt;&lt;strong&gt;
&lt;h2&gt;&lt;strong&gt;XML request error: Ok (200)&lt;/strong&gt;&lt;/h2&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/strong&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The same error again. Good. That means it is not about the data. Response looks like it is scrambled or packed when it comes to the client side! 
&lt;/p&gt;
&lt;p&gt;
That is a clue. Let&amp;rsquo;s investigate an interesting property of the Response object. It is the Filter property. 
&lt;/p&gt;
&lt;p&gt;
Response.Filter is a stream that is used to process data before it is sent to browsers, so if you, for example like to convert all cases to upper this is the place for your custom stream. 
&lt;/p&gt;
&lt;p&gt;
I investigated that property and found its value interesting. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/FCKEditorwithASP.NETFixTheserverdidntse/228411DE/deflatestream_image4.jpg"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px; border: 0px" src="http://www.icodefactory.com/lab/image.axd?picture=WindowsLiveWriter/FCKEditorwithASP.NETFixTheserverdidntse/1F5EFD6B/deflatestream_image4_thumb.jpg" border="0" alt="deflatestream_image4" title="deflatestream_image4" width="244" height="122" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
There was a DeflateStream object. This means response is compressed by server and sent to client as a compressed stream. This is why I got and strange encoded characters as error. 
&lt;/p&gt;
&lt;p&gt;
Fix was easy. I added one line of code: 
&lt;/p&gt;
&lt;p&gt;
Response.Filter = null; 
&lt;/p&gt;
&lt;p&gt;
private static void SetupResponse( HttpResponse response ) 
&lt;/p&gt;
&lt;p&gt;
{ 
&lt;/p&gt;
&lt;p&gt;
// Cleans the response buffer. 
&lt;/p&gt;
&lt;p&gt;
response.ClearHeaders(); 
&lt;/p&gt;
&lt;p&gt;
response.Clear(); 
&lt;/p&gt;
&lt;p&gt;
&lt;u&gt;&lt;em&gt;&lt;strong&gt;response.Filter = null;&lt;/strong&gt;&lt;/em&gt;&lt;/u&gt; 
&lt;/p&gt;
&lt;p&gt;
// Prevent the browser from caching the result. 
&lt;/p&gt;
&lt;p&gt;
response.CacheControl = &amp;quot;no-cache&amp;quot;; 
&lt;/p&gt;
&lt;p&gt;
// Set the response format. 
&lt;/p&gt;
&lt;p&gt;
response.ContentEncoding = System.Text.UTF8Encoding.UTF8; 
&lt;/p&gt;
&lt;p&gt;
response.Charset = &amp;quot;utf-8&amp;quot;; 
&lt;/p&gt;
&lt;p&gt;
response.ContentType = &amp;quot;text/xml&amp;quot;; 
&lt;/p&gt;
&lt;p&gt;
} 
&lt;/p&gt;
&lt;p&gt;
Build the solution and run it again. It works. 
&lt;/p&gt;
&lt;p&gt;
It was simple fix, but a very hard one to find. What is most amazing for me is that it was not found by other members of the community so far. I hope this article will help. Does it? 
&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/isWRnnIlQtA" height="1" width="1"/&gt;</summary>
    <published>2009-07-07T15:47:00+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/FCKEditor-with-ASPNET-Fix-The-server-did-not-send-back-a-proper-XML-response-error.aspx#comment" />
    <category term="ASP.NET" />
    <dc:publisher>Sergio</dc:publisher>
    <dc:description>FCKEditor fix for strange issue with file manager.</dc:description>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=20d0349b-1189-443e-b00d-a28b5a91f980</pingback:target>
    <slash:comments>101</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=20d0349b-1189-443e-b00d-a28b5a91f980</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/FCKEditor-with-ASPNET-Fix-The-server-did-not-send-back-a-proper-XML-response-error.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=20d0349b-1189-443e-b00d-a28b5a91f980</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/FCKEditor-with-ASPNET-Fix-The-server-did-not-send-back-a-proper-XML-response-error.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/ASPNET-35-ListView-control-Is-it-perhaps-too-early.aspx</id>
    <title>ASP.NET 3.5 ListView control - Is it perhaps too early?</title>
    <updated>2009-07-03T09:50:00+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=3348cc53-4c9e-400a-a8f6-82fbdba16f8c" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/Gvif4NAEcmo/ASPNET-35-ListView-control-Is-it-perhaps-too-early.aspx" />
    <author>
      <name>Lacio</name>
    </author>
    <summary type="html">&lt;p&gt;
The ListView control was introduced with asp.net 3.5 as an alternative to the existing data bound controls. It offers much more possibilities than the other controls, plus it generates clean html code, that will display just the way you tell it to. It offers all the possibilities of the other controls combined - selection, sorting etc. Despite all of this sounding quite nicely, it still has some unresolved issues that might hinder its usage in the early stages.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Being accustomed to using drag&amp;amp;drop and free naming techniques, the first strange thing that popped to my mind the first time I used the control was the need to name the itemplaceholder exactly &amp;quot;itemPlaceholder&amp;quot;. That was strange at first, but only later&amp;nbsp; have I realised that this was a clever method to transform any control running on client side into a potential place holder for the item templates defined by the ListView control. However, I still found it strange that the name has to be hard coded, otherwise the control won&amp;#39;t work. Why couldn&amp;#39;t they add a property that holds the name of the itemplaceholder, instead of explicitly being forced to name it like that.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
After coping with this annoying issue all in the name of being able to use a great new control that is still better then any of the other ones - it enables selected item template - which beats the repeater - and it generates the html you tell it to generate - unlike the datalist control, which is really messed up here, I found another really strange issue. I am not sure if anyone has encountered this problem, I did some short googling on the issue, and haven&amp;#39;t found any spot-on fixes. Either people are not using the control, or I have a very specific version of the .net framework and it just won&amp;#39;t obey commands from my keyboard :).
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The issue happens when raising the SelectedIndexChanged event - first of all, it requires the SelectedIndexChanging event to even work. If you don&amp;#39;t specify the indexChanging event, the compiler will report an issue. If you manage to get it started however, you are about to hit another unpleasent surprise. If you expect it to run normally, it won&amp;#39;t - when having the select command the index will always be lagging by one step - The selected index will always be the next to last item you selected. The way to fix this is by set the selected index in the method raised by the SelectedIndexChanging event. This way, when you get to the selectedIndexChanged event, you will have the correct index and it will show it selected on the page.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Doing some research has revealed that it is the least used control of them all. For me personally, once you learn how to tame it, it becomes a very powerfull tool to display data. I believe that with the coming of the new version of asp.net the control will mature a bit &lt;br /&gt;
and become a regular feature on sites worldwide.
&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/Gvif4NAEcmo" height="1" width="1"/&gt;</summary>
    <published>2009-07-03T09:50:00+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/ASPNET-35-ListView-control-Is-it-perhaps-too-early.aspx#comment" />
    <category term=".NET" />
    <category term="ICF.Labs" />
    <category term="State of Mind" />
    <dc:publisher>Lacio</dc:publisher>
    <dc:description>A short comment on the listview control</dc:description>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=3348cc53-4c9e-400a-a8f6-82fbdba16f8c</pingback:target>
    <slash:comments>171</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=3348cc53-4c9e-400a-a8f6-82fbdba16f8c</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/ASPNET-35-ListView-control-Is-it-perhaps-too-early.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=3348cc53-4c9e-400a-a8f6-82fbdba16f8c</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/ASPNET-35-ListView-control-Is-it-perhaps-too-early.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/UAC-Revealed-7e-elevation-of-rights-from-NET-as-commonly-misunderstood.aspx</id>
    <title>UAC Revealed ~ .elevation of rights from .NET as commonly misunderstood.</title>
    <updated>2009-06-08T14:19:00+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=92b85af7-a9ce-4f7d-9d0f-4afbce4624da" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/_bGWpiHCeVQ/UAC-Revealed-7e-elevation-of-rights-from-NET-as-commonly-misunderstood.aspx" />
    <author>
      <name>Sergio</name>
    </author>
    <summary type="html">&lt;p&gt;
Recently we had a project that involves impersonification of windows users. 
&lt;/p&gt;
&lt;p&gt;
Idea was to create a tool that will allow non admin domain user to start single executable that requires administrative rights without need to add domain user to administrators group.&lt;br /&gt;
So, we were planning to create command prompt tool that may process parameters, impersonate some other user (administrator) and starts another process with new user&amp;rsquo;s credentials. 
&lt;/p&gt;
&lt;p&gt;
We made a small proof of concept and it all worked well. Nice, I sad, let&amp;rsquo;s test it with Vista&amp;rsquo;s User Access Control. Whoops! 
&lt;/p&gt;
&lt;p&gt;
Newly started process, starts as admin user, but without elevated rights. That means user is administrator, but run with rights of regular user! 
&lt;/p&gt;
&lt;p&gt;
So we got &amp;ldquo;this process needs elevation&amp;rdquo; error in console window. 
&lt;/p&gt;
&lt;p&gt;
After some investigation on internet we found ProcessStartInfo.Verb property as point of interest in this case.&lt;br /&gt;
According to number of articles, you just need to set this property&amp;rsquo;s value to &amp;lsquo;runas&amp;rsquo; and new process will be started with elevated rights. As if.&lt;br /&gt;
This approach would not help you in this case. Actually there is no solution for UAC!&lt;br /&gt;
&lt;br /&gt;
We contacted Microsoft&amp;rsquo;s forums, and after number of posts and responses we discovered the awful truth.&lt;br /&gt;
There is no way to start another process from .net code, impersonate another user to execute that code and elevate rights for that user.&lt;br /&gt;
Actually there is no way to do it with UAC enabled. It is constraint of UAC itself. UAC will not allow you to do this. &lt;br /&gt;
Microsoft claims that this is security measure, but in my opinion it does not have too much sense since my code already knows administrator user&amp;rsquo;s credentials!&lt;br /&gt;
So, what kind of protection is this anyway?&lt;br /&gt;
Next thing that was really strange to me is why so many articles claim opposite?&lt;br /&gt;
(Take a look at: &lt;a href="http://victorhurdugaci.com/using-uac-with-c-part-1/"&gt;http://victorhurdugaci.com/using-uac-with-c-part-1/&lt;/a&gt; for example.)&lt;br /&gt;
&lt;br /&gt;
Problem is that there are some administrative users that are not controlled by UAC!&lt;br /&gt;
Built in local administrator user or build in domain administrator user are not constrained by UAC.&lt;br /&gt;
&lt;br /&gt;
This means that you may start another process from your .net code, impersonate built in administrator user and new process will start elevated!&lt;br /&gt;
So this code snippet: 
&lt;/p&gt;
&lt;p&gt;
&lt;font face="courier new,courier"&gt;ProcessStartInfo processInfo = new ProcessStartInfo();&lt;br /&gt;
SecureString securePassword = new SecureString();&lt;br /&gt;
foreach (char ch in &amp;ldquo;testpass&amp;rdquo;)&lt;br /&gt;
{&lt;br /&gt;
securePassword.AppendChar(ch);&lt;br /&gt;
} // foreach&lt;br /&gt;
processInfo.UserName = &amp;ldquo;administrator&amp;rdquo;;&lt;br /&gt;
processInfo.Password = securePassword;&lt;br /&gt;
processInfo.Verb = &amp;ldquo;runas&amp;rdquo;;&lt;br /&gt;
processInfo.FileName = @&amp;rdquo;c:\windows\system32\cmd.exe&amp;rdquo;;&lt;br /&gt;
processInfo.UseShellExecute = false;&lt;br /&gt;
Process.Start(processInfo);&lt;br /&gt;
&amp;hellip;&lt;/font&gt; 
&lt;/p&gt;
&lt;p&gt;
Will run cmd.exe elevated on Vista, because this user is not run as regular user, but as full rights administrator!&lt;br /&gt;
But, if you try to use any other member of administrators group as as new process user it will not work!&lt;br /&gt;
&lt;br /&gt;
Unfortunately it has been an &amp;lsquo;show stopper&amp;rsquo; for our project. Too bad. 
&lt;/p&gt;
&lt;p&gt;
By my first investigation it will&amp;nbsp; be possible by default on Windows 7! Now, that is interesting. 
&lt;/p&gt;
&lt;p&gt;
I wonder did we found a bug in UAC design or .NET implementation? Maybe. The World will know;-) 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/_bGWpiHCeVQ" height="1" width="1"/&gt;</summary>
    <published>2009-06-08T14:19:00+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/UAC-Revealed-7e-elevation-of-rights-from-NET-as-commonly-misunderstood.aspx#comment" />
    <category term=".NET" />
    <dc:publisher>Sergio</dc:publisher>
    <dc:description>UAC and .NET - As commonly misunderstood.</dc:description>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=92b85af7-a9ce-4f7d-9d0f-4afbce4624da</pingback:target>
    <slash:comments>268</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=92b85af7-a9ce-4f7d-9d0f-4afbce4624da</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/UAC-Revealed-7e-elevation-of-rights-from-NET-as-commonly-misunderstood.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=92b85af7-a9ce-4f7d-9d0f-4afbce4624da</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/UAC-Revealed-7e-elevation-of-rights-from-NET-as-commonly-misunderstood.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/Test-Driven-Development-Yes-or-No.aspx</id>
    <title>Test Driven Development ~ Yes or No</title>
    <updated>2009-05-24T23:24:00+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=74db2529-da21-4fcb-9190-c6de4ecf9626" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/8DlWA4QzSLM/Test-Driven-Development-Yes-or-No.aspx" />
    <author>
      <name>Sergio</name>
    </author>
    <summary type="html">&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;Currently as being in Germany and working on client&amp;#39;s site I met an interesting project.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;&lt;/span&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;Product that our team is working on with the client is developed on TDD practices.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;NUnit, CruiseControl.NET and NCover are used to support development.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;&lt;/span&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;I now wonder why TDD is not used more on other projects. There are a number of common reasons people exposes.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 13.5pt"&gt;&amp;ldquo;It takes too much time to write tests. I code faster without it.&amp;rdquo;&lt;/span&gt;&lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 13.5pt"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;This is I guess number one complaint voiced by developers. It is untrue. And it is simple.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;Many people view testing of any sort as something that happens at the end of a project. And it is somehow true, but not completely. &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;It is more related to acceptance tests for example. &lt;/span&gt;&lt;span style="font-family: 'Times New Roman','serif'; font-size: 12pt"&gt;&lt;/span&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;If you try to add unit test at the end of project, you will fail,&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;&lt;/span&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;but if you use &amp;quot;pay as you go&amp;quot; logic and start with tests at the beginning, you will get solid, tested code, and will definitely have less bugs.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
This means that you will not produce 2 lines of code daily at the end of project just because you are searching for an tricky bug. 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;&lt;/span&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;This is especially true for &amp;quot;heavy to debugg&amp;quot; issues in nearly finished projects when deadline is so close that you feel dizzy.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;&lt;/span&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 8.5pt"&gt;There are a number of other excuses for not using TDD, but this one is somehow first one to beat.&lt;/span&gt;&lt;font face="Calibri" size="3"&gt;&amp;nbsp;&lt;/font&gt; 
&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/8DlWA4QzSLM" height="1" width="1"/&gt;</summary>
    <published>2009-05-24T23:24:00+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/Test-Driven-Development-Yes-or-No.aspx#comment" />
    <category term="State of Mind" />
    <dc:publisher>Sergio</dc:publisher>
    <dc:description>Test Driven Development helps you build solid, well tailored code. Still, there are some people that do not like TDD. This is one common newcomers reason.</dc:description>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=74db2529-da21-4fcb-9190-c6de4ecf9626</pingback:target>
    <slash:comments>22</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=74db2529-da21-4fcb-9190-c6de4ecf9626</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/Test-Driven-Development-Yes-or-No.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=74db2529-da21-4fcb-9190-c6de4ecf9626</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/Test-Driven-Development-Yes-or-No.aspx</feedburner:origLink></entry>
  <entry>
    <id>http://www.icodefactory.com/lab/post/Welcome-to-ICF-Labs.aspx</id>
    <title>Welcome to ICF labs</title>
    <updated>2008-06-28T23:00:00+00:00</updated>
    <link rel="self" href="http://www.icodefactory.com/lab/post.aspx?id=c3b491e5-59ac-4f6a-81e5-27e971b903ed" />
    <link href="http://feedproxy.google.com/~r/icodefactory/~3/RAflJpbkboc/Welcome-to-ICF-Labs.aspx" />
    <author>
      <name>Admin</name>
    </author>
    <summary type="html">&lt;p&gt;
This section is still under development, but when finished, you will be able to see interesting guides, hands-on experiences, helpfull tips and a host of other nice articles. 
&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/icodefactory/~4/RAflJpbkboc" height="1" width="1"/&gt;</summary>
    <published>2008-06-28T23:00:00+00:00</published>
    <link rel="related" href="http://www.icodefactory.com/lab/post/Welcome-to-ICF-Labs.aspx#comment" />
    <category term="ICF.Labs" />
    <dc:publisher>Admin</dc:publisher>
    <dc:description>welcoming post to the icf labs section</dc:description>
    <pingback:server>http://www.icodefactory.com/lab/pingback.axd</pingback:server>
    <pingback:target>http://www.icodefactory.com/lab/post.aspx?id=c3b491e5-59ac-4f6a-81e5-27e971b903ed</pingback:target>
    <slash:comments>23</slash:comments>
    <trackback:ping>http://www.icodefactory.com/lab/trackback.axd?id=c3b491e5-59ac-4f6a-81e5-27e971b903ed</trackback:ping>
    <wfw:comment>http://www.icodefactory.com/lab/post/Welcome-to-ICF-Labs.aspx#comment</wfw:comment>
    <wfw:commentRss>http://www.icodefactory.com/lab/syndication.axd?post=c3b491e5-59ac-4f6a-81e5-27e971b903ed</wfw:commentRss>
  <feedburner:origLink>http://www.icodefactory.com/lab/post/Welcome-to-ICF-Labs.aspx</feedburner:origLink></entry>
</feed>

