Using Asp:menu and XmlDataSource

I’ve started to use  Asp:menu with XmlDataSource based on Quick Start Example.

To show many top level elements I tried to specify XPath, but failed to do it correctly(probably due to missing XML namespace).
So I changed the XML schema aa suggested in Asp.Net Menu Control Binding with XMLDataSource  and used XPath=”/Home/Menu” to not show single root Item.

Unfortunately DataBinding doesn’t support default properties in XML file.All nodes must have all attributes, specified in DataBinding  section.
Otherwise InvalidOperationException like the following will be shown:
Could not bind to the ‘Selectable’ property (specified by SelectableField) while databinding Menu. Please check the Bindings fields. 

It was a requirement to show top left menu item differently than other top menu.I was able conditionally specify first node of a few siblings using “Home/menu[1]|” Then I was about to use Templates and follow approach from Customise Individual Menu Items article .But suddenly I understood, that it is simpler to have left top menu as one control and other menus as second control with diferent behavior -KISS.

Problems after Installing VS 2008 side-by-side with VS 2005

I have Visual Studio 2005 environment and decided to try VS 2008. I’ve read some articles(e.g. here) about site-by-site installation and had an impression, that making a copy of solution is enough.

NOTE: If you are using TFS, before conversion of the existing solution, obtain and install  Team Explorer Client .
VS 2005 is using TFS Source Control, but VS 2008 shows no Source Control plug-in installed.

After installing of VS 2008  I’ve copied my existing solution as MySolution2008 and opened it in Visual Studio 2008. The upgrade wizard told me that upgrade will be done in place(no backup option in the wizard) Then it showed that it converted also project files.

Then I open original Solution2005.sln in VS 2005. However wizard suggested me to upgrade to the latest version< so I wasn’t able to open existing solution in VS 2005.I’ve followed the recomendation to restore file association in VS from Tools->option->Environment->General , then click the  “Restore File Assoications” button on the dialogue.

It allowed me to open solution in 2005. However I’ve noticed that generated files (such as typed datasets and web references) were modified.The reason is that the projects were updated with extra attributes

<Project DefaultTargets=”Build” xmlns=”″ ToolsVersion=”3.5“>

and extra elements <OldToolsVersion>2.0</OldToolsVersion>.

Furthermore, for a few projects it was recommended  to open in Browse mode, because they have unsafe Includes. It also changed the path

<Import Project=”$(MSBuildExtensionsPath)MicrosoftVisualStudiov9.0WebApplicationsMicrosoft.WebApplication.targets” Condition=”” />

After fixing these changes I was able to restore my VS 2005 solution back to normal.
The similar posts , that helped me, are Moving Projects/Solutions between Orcas and Visual Studio 2005 ,
Rick Strahl‘s ‘Migrating Web Application Projects between VS 2005 and VS 2008
Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!  -shows how to add conditional entries Condition=”‘$(Solutions.VSVersion)’ == ‘8.0’”/>


References to AJAX DLLs

After a few weeks after VS 2008 installation after reboot I’ve noticed that my web.config got extra
<add assembly=”System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>
    <add assembly=”System.Core, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089″/>
    <add assembly=”System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089″/>

It caused WMIPRVSE.EXE to take 100% CPU , because of endless errors:

System.Web.HttpCompileException: error CS0433: The type ‘System.Web.UI.ScriptManager’ exists in both ‘c:WINDOWSassemblyGAC_MSILSystem.Web.Extensions3.5.0.0__31bf3856ad364e35System.Web.Extensions.dll’ and ‘c:WINDOWSassemblyGAC_MSILSystem.Web.Extensions1.0.61025.0__31bf3856ad364e35System.Web.Extensions.dll’

I had to delete the extra entries.

WCF vs .Net remoting Notes

We are using .Net remoting now between Web Server and Application Server farms. I am consider to use WCF for new modules.

Good news: The WCF and .NET Remoting are really comparable in performance. and according to MSDN article A Performance Comparison of Windows Communication Foundation (WCF) with Existing Distributed Communication Technologies WCF  even approximately 25% faster.  

I hope to extend this post when I will collect more info.

DateTime value in DataSet changed over remoting boundaries.

We are using .Net remoting(.Net framework 2.0) to pass DataSet from application server to web server.
It was noticed that if DateTime field in DataSet has ‘2008-10-26 02am” value, during remoting it is changed to ‘2008-10-26 03am“.
I beleive that it is somehow relates to Daylight Saving time change. We didn’t noticed any changes for other DateTime values.
According to  Western Australia (Perth)  has time change 26-Oct, 02:00h.
However the servers with the problem noticed are located in Melbourne and Sydney, that have different date for Daylight Saving time change.(See also
Furthermore my development machine doesn’t have this problem -‘2008-10-26 02am” is transferred unchanged.
We haven’t found any essential differences in settings between machines that have the problem and my deveopment machine. It may be related to some MS hotfix update(??). However other machines with and without .Net framework 2 SP1 have the same problem.
Update: Reader of my post asked how to send DateTime values in a DataSet with DayLight saving considerration, but then pointed that .Net 2.0 and greater has ability to specify DataSetDateTime.Unspecified  enum value(“Serialization in this mode does not cause an offset”)  in DataColumn.DateTimeMode Property. It will make DateTime values in a dataset predictable regardless of server local time settings.
Also note that in .Net 3.5 there is TimeZoneInfo Class that suppose to help with cross-zone issues.

Insert new lines in XML text using Visual Studio.

UPDATE: I’ve recently was adviced that I can use VS command Edit/Advanced/Format Document(Ctrl-K,Ctrl-D) and it does better formating.

I ‘ve got XML files as one long string, not formatted. IE explorer shows them nicely with all indentation and ablility to collapse parts.
However to edit or compare files using Windiff or Winmerge it will be convinient to have them with short lines, e.g. each element in a new line.

Fortunately VS has ability to insert new lines in replace operation.
1.Click Ctrl-H
2. Tick “Use Regular Expressions”
3. In Find specify [>]
4. In Replace specify n.
5 Click “Replace All”
After all XML “>” characters a new line will be inserted.

I also used the same approach to insert line breaks into HTML files.

Html Form inside ASP.Net page causes no postbacks

I needed to re-design an existing page to include new html, created by third party designer.
After I’ve done the changes, I found that postbacks are not working.
It took me a while to understand that the cause of the problem is an html form, included in the main ASP.Net form like the following:

  <form method=”post” action=”about/subscribe/” id=”Mail”><input type=”text” value=”Enter your email address” name=”mail” class=”field-subscribe”/>

<input type=”image” align=”middle” class=”field-go” src=”Images/button_goheader.gif” value=”Go”/>


Note that buttons before html form are sending postbacks correctly, but those that are after the form in the html, are broken.  

So I  removed form, but  posted field to external URL  using PostBackUrl property:

 <asp:ImageButton ImageUrl=”~/Images/button_goheader.gif” PostBackUrl=”about/subscribe/” runat=”server” ToolTip=””Go“” align=”middle” class=”field-go” />

As an option, html form can be put into separate page and inserted into IFRAME on the main form.

Community Content Top Contributor Award

I have been selected to receive one of 20 Community Content Top Contributor Awards for your contributions to the MSDN wiki in 2007.

Good news.

 I’ve tried to find in MSDN how many topics I’ve added and it wasn’t easy. MSDN Library  shows only top 5. My profile doesn’t show it. I had to search MSDN for my name, open the topic, open each version to find my post and then click on my name.

Now I know the pattern
For today I have:

Blocks Created: 35
Blocks Edited: 37  



Function to Strip Html Tags

I have a string that include HTML tags <B> font etc. I want to Strip Html Tags to show the string as tooltip.
Thanks to HtmlAgilityPack it is easy:

      public static string StripHtmlTags(string html)
            if(String.IsNullOrEmpty(html)) return “”;
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            return doc.DocumentNode.InnerText;

TableCell.Text property is ignored if there are child controls

I wanted to dynamically create content of ASP.NET TableCell control. It should have some text and image.
I’ve tried to use the code

cell.Text = “Text”;

But the text wasn’t shown. The reason is that if TableCell has child controls, the text value is ignored during rendering. See TableCell.RenderContents in Reflector.

The valid way is the following:
Label lbl=new Label();

Passing null parameters to String.Format is safe

I wanted to use String.Format with parameters that can be null. Firstly i decided to put some conditional code like
if(arg1!=null) but then desided to check, if it is handled automatically. And from Reflector it looks that it handles nulls

if (str2 == null)
        str2 = string.Empty;
So it safe to write code like 

String.Format(“({0}{1})”, a1,a2 ) ,

even if some parameters are null.