Category Archives: Development – .NET
Infragistics WebCombo single quote workaround
With EnableXmlHttp and ComboTypeAhead enabled, WebCombo becomes an AJAX google alike dropdown. But there is a bug (as of version 6.3) in handling single quote, it has javascript error.
So, here is my workaround:
 
And Of course, you need to add this client side event to your WebCombo:
 
�
X-tensive DataObject.NET v3.9.5 Upgrade
I have been using X-tensive DataObject.NET (“DO”), an object persistence layer for the .NET Framework for 3 years on my side businesses. “DO” is the most and extremely powerful software I have ever purchased, these Russian guys really rock! It’s true object oriented and I hope I can use this on my full time job, but at work we use SOA model via web services on relational DB using Microsoft Enterprise Library. well… I have no comments on that.
Back to the topic, having running “DO” v3.8.x for 2 years and v3.9.5 upgrade has been the most difficult one, I couldn’t find any official 3.8.x to 3.9.x upgrade guide, so here is a couple notes that may help you:
1. Web.config: (easy) There are some XML changes, refers to latest version of DoPetShop sample. It added “domains” in the XML, etc.
2. DataContext.cs: (easy) Copy and paste from DoPetShop
3. Global.asax.cs: (difficult)Â Disable any DoPetShop related stuff
Problem: All my databases tables and views are having OWNER = “dbo” (due to ISP restriction), and I got “Specified owner name ‘xxxx’ either does not exist or you do not have permission” on Domain.build();
Solution: http://x-tensive.com/Forum/viewtopic.php?t=3284
4. All your .cs Source code (time consuming): Because v3.9.x made many methods become obsolete, I recommend upgrading. The problem is the x-tensive XML doc has no guideline to tell you what new method to use, you either have to look it up in the forum or dig up the DoPetShop source code. Here are the most commonly obsoleted methods:
old: objectName.ID
new: objectName.Key.ID
old: RemoveObjects(queryResult.GetIds())
new: RemoveObjects(queryResult.GetKeys())
old: DataContext.Session[id]
new: DataContext.Session[new Key(id)]
Hope this helps!
Visual Studio 2005 bug – Publish empty Web Site
Problem:
In VS2005, publish web site resulting an empty folder. However, pre-compiled successfully was shown in VS2005, but never able to find the files.
Reference:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1091645&SiteID=1
Solution:
Search for the FORM tag and found one unclosed tag. The compiler should have given an error message, I think this is a bug.
Could not load file or assembly ‘App_Web_xxxxxxxx,’..
Problem:
Could not load file or assembly ‘App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.
Reference:
http://support.microsoft.com/kb/915782/en-us
http://forums.asp.net/thread/1271201.aspx
Solution:
The only Temporary fix is to make a small change in the offending user control, and copy it to the production server.
No hardcoding path in ComponentArt:Menu ClientTemplate
Problem: Component Art MENU component is extremely powerful, it supports ClientTemplates like the .NET Repeater. However, the template is for client side only and we had to hardcode the path in XML if virtual directory is used. We can’t use “/” and “~/” for the root.
Solution: Since Component Art uses Data Binding, we can use ItemDataBound to solve this problem easily. With the Request.ApplicationPath, the path can dynamically generated on the server without hardcoding in the XML site map file.


Breadcrumbs Trail – SiteMapPath without showing ROOT
Problem: I am looking for solution to hide the Root in Breadcrumbs of ASP.NET SiteMapPath. This can be done easily in SiteMap by setting the attribute in the datasource. However this is not the same in BreadCrumbs. Well, I couldn’t find a complete solution on the Internet, yet the following 2 articles are valuable references:
Article 1 – This article clones the Sitemap nodes on the global.asax level, it doesn’t work well when it hits the root. (I am using .NET 2.0) Also, there are some other problems reported by other uses.
Article 2 – This article is awesome, the authors teaches you how to make individual node show or hide, however it still doesn’t solve the SiteMapPath not showing ROOT!
Solution:
In .ASPX.CS:

In .ASPX:

(This blog software is so buggy and does not handle C# code well, not even with plug-in.  I even converted it to HTML friendly characters in Dreamweaver, and still didn’t work in HTML mode. So I gave up and post a JPG instead. Sorry, no copy and paste code.)
Remarks: We define 3 templates: one for ROOT, one for Node and one for Current Node. As you can see, the RootNodeTemplate shows nothing therefore the ROOT won’t show up. The problem is the seperator, so we need two methods to check ROOT to decide to show the seperator or not.
AJAX on .NET Development Notes
I have been working on AJAX Pro for .NET and Anthem.NET on various projects, and here are the tips and general rules you may want for reference to prevent nightmere in debugging:
1. Why does AJAXÂ not working at all and doesn’t give an error message?
Check if you have the FORM tag with runat=”server”
2. Why is AJAX working  but sometimes does not work?
Check if your site is using form or Windows authentication, note that AJAX calls on the background does not always carry the authentication for some odd reasons.
3. When multiple browsers is used and run the AJAX application at the same time, something is mixed up but couldn’t figure out why?
As a general rule in any programming language, variables must never be initialized in the declaration area, it should be done in Page_Load()
e.g. private string id = 1234;
This is very bad and it does not guarentee 1234 will be assigned to the variable when page is loaded. Most of the time this will work on server side coding, but not always in Javascript world.
Remember, AJAX creates Javascript proxy from the server side code. In the old days when we did Javascript, all initialization had to be done using onload=”…” on the body tag.
4. As a general rule, do not use static method or static class, it can cause problem when multiple instances of AJAX share the same instance. Create instance of an object if possible for each thread. This happens to Java Applet too!
5. Make sure you understand the difference between PostBack (.NET) and CallBack (AJAX) on when to use Page.IsPostBack (.NET) and when to use UpdateAfterCallBack (AJAX/Anthem)
Reading XML
Code Snippets for quick reference:
XmlTextReader reader = new
XmlTextReader(Server.MapPath("Data.xml"));
   Â
object idObject = reader.NameTable.Add("ID");
object firstNameObject = reader.NameTable.Add("FirstName");
string id = "";
string firstName = "";
while (reader.Read())
{
 if (reader.NodeType == XmlNodeType.Element)
 {
  // WARNING: not good programming,
       // this forces it to read a pair
       // but it works (assuming it is well-formed XML)
  if (reader.Name.Equals(idObject))
  {
   id = reader.ReadString();
   reader.Read();
  }
  if (reader.Name.Equals(firstNameObject))
  {
   firstName = reader.ReadString();
   reader.Read();
  }
 } // if
 if ((reader.Name.Equals(idObject)) ||
  (reader.Name.Equals(firstNameObject)))
 {
  Response.Write(id + " " + firstName);
 } // if  Â
} // while
reader.Close();
DataSet Traversal
Code Snippet for quick reference:
DataSet resultDataSet;
DataTable dataTable = resultDataSet.Tables[0];
// Get Column names
for (int i = 0; i < dataTable.Columns.Count; i++)
{
 Response.Write(dataTable.Columns[i].ToString();
}
// Get the actual data
for (int i = 0; i < dataTable.Rows.Count; i++)
{
 DataRow dataRow = dataTable.Rows[i];
 for (int j=0; j < dataRow.Table.Columns.Count; j++)
 {
 Response.Write(dataRow.Table.Rows[i][j].ToString());
 } // for
}
After .NET 2.0 upgraded, got “Request timed out” error
After upgrading the web services (*.ASMX) to .NET 2.0 from .NET 1.1, the report project I was working on got “Request Timed out” error. The reports are very complicated and it usually takes several minutes to generate, therefore in the old .NET 1.1 code web.config file, I already had this to make it timeout after 15 min:
httpRuntime executionTimeout="900"
However, after .NET 2.0 upgrade that didn’t help. After debugging for 2 full days by tracing every single line of code. I figured out it was caused by the request length! So, I added the following line to the web config file, all of the web services worked fine without timeout error.
httpRuntime executionTimeout="900" maxRequestLength="902400"
Perhaps .NET 1.1 default maxRequestLength is longer than .NET 2.0? maybe someone can verify that for me.