Friday, January 23, 2009

ASP.NET 2.0 Multiline TextBox submits on enter in Firefox

I'm sure I've run into this issue before. If a form contains a asp:TextBox with TextMode="MultiLine" and you press enter in the textbox to create a new line the entire form gets submitted to the server in Firefox.

In my case Firebug revealed that the textarea was nested in a asp:Panel where onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl03_ctl05_btnSubmit')"

A little Googling on FireDefaultButton reminded me that its implementation is IE specific. The following article shows how to register a client script include that will update the function.

Multi-line Text boxes and the DefaultButton in ASP.NET 2.0

The same issue is also discussed on StackOverflow: Asp.Net Form DefaultButton Error in Firefox and StackOverflow: enter key to insert newline in asp.net multiline textbox control

function WebForm_FireDefaultButton(event, target) {
 if (event.keyCode == 13) {
 var src = event.srcElement || event.target;
 if (!src || (src.tagName.toLowerCase() != "textarea")) {
 var defaultButton;
 if (__nonMSDOMBrowser) {
 defaultButton = document.getElementById(target);
 }
 else {
 defaultButton = document.all[target];
 }
 if (defaultButton && typeof(defaultButton.click) != "undefined") {
 defaultButton.click();
 event.cancelBubble = true;
 if (event.stopPropagation) event.stopPropagation();
 return false;
 }
 }
 }
 return true;
}

Sitecore Australia User Group

The Sitecore Australia user group (SCAUG) is to become a center for sharing knowledge and practical experience for Australian and New Zealand Sitecore developers and enthusiasts.

Tuesday, January 20, 2009

Converting Salesforce API DateTime from UTC to the users timezone using TimeZoneSidKey

With .NET 3.5 the System.TimeZoneInfo class can be used to convert the UTC DateTime to the users time zone, including changes required for daylight savings. The basic steps involve:
  GetUserInfoResult userInfo = binding.getUserInfo();
  string userTimeZoneSidKey = userInfo.userTimeZone;

  string timeZoneKey = string.Empty;
  switch (userTimeZoneSidKey)
  {
    case "America/Los_Angeles":
      timeZoneKey = "Pacific Standard Time";
      break;
    case "Pacific/Auckland":
      timeZoneKey = "New Zealand Standard Time";
      break;
    //...
  }

  TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneKey);
  DateTime timeZoneDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, 
     timeZone);
The pain point here is the huge switch statement required to map the Salesforce TimeZoneSidKey to a valid TimeZoneInfo Id. See also:

Sitecore 6 C# snippets including item URL

Sitecore.Context

Sitecore.Context.Item the requested URL's target item.

Get the URL for an item

string urlOfItem = Sitecore.Links.LinkManager.GetItemUrl(item);

string currentItemUrl = Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item);

Get the full URL for an item

Sitecore.Links.UrlOptions urlOptions = Sitecore.Links.LinkManager.GetDefaultUrlOptions(); 
urlOptions.AlwaysIncludeServerUrl = false;
string currentItemUrl = Sitecore.Links.LinkManager.GetItemUrl(sample,urlOptions);

Get an items field value

string fieldValue = item["fieldname"];
FieldRenderer.Render(item, "fieldname");

Children

Sitecore.Collections.ChildList children = item.GetChildren(ChildListOptions.None);

Thursday, December 18, 2008

Monday, December 15, 2008

Object-relational impedance mismatch

Recently I found myself discussing how to an application accesses data in a database. This Wikipedia article has some good arguments for an Object-relational mapping approach. http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch

Thursday, December 4, 2008

Log file monitoring for log4net output

I was thinking of building a C# UDP listener to connect a log4net UDP appender to. Something like this - Code Project: A log4net Realtime Color Console for ASP.NET

The trick would be getting a setup that would work for multiple developers. A service that accepts the UDP packets and relays them out to registered listeners or something such similar.

After some quick Googling I found it would be quicker to have each developer just point a log monitoring tool at the output from a RollingFileAppender. BareTail seems to do a pretty good job.

Updated: When combined with a RollingFileAppender using XmlLayout Log4view works well to filter out the loggers.