I came across an interesting behavior today. I was dynamically loading a user control into a RadTooltip using Page.LoadControl("MyUsercontrol.ascx")

Canceling the tooltip causes a partial-page postback. If I then reopen the tooltip before I do something to cause a full-page postback, the user control in the tooltip loads with the cached control state from the canceled instance. It appears that the second call to Page.LoadControl() returns an object with the same ID, and ASP.NET automatically wired it up.

My solution: in an event handler for the user control's Cancel button, I change the user control's ID to some throwaway text, like ...

I've been working on a multilanguage web site using ASP.NET localization. I wanted to return unique meta tags for each page in the user's language. There are a handful of ways to accomplish this (MasterPage codebehind, base page codebehind, etc); here's the approach I took:

  1. My web site was already taking advantage of Web.Sitemap, so I decided it would be best to store the meta tags there as a custom attribute. Web.Sitemap's resources can be globalized, so I actually don't need to do anything special to the sitemap besides set enableLocalization="true" and assign a unique resourceKey attribute if one does ...

Most UI elements in Silverlight have a Focus() method, but because of a known bug in Silverlight 3, calling that method does not actually give the element focus! One workaround is to first call the UpdateLayout() method of the element, and then call Focus(). For example, if I have an TextBlock called txtName that I would like to have focus on load, I could do this: 

public MainPage()
{
    InitializeComponent();
    txtName.UpdateLayout();
    txtName.Focus();
}


If this element is not directly on a page but instead is in a control, this approach may not work. In that case, wire ...

I've recently installed Windows 7 on a powerful desktop and a netbook. For the most, it's been an easy transition, but every so often I'll run into little quirks.

I use the excellent TortoiseSVN (http://tortoisesvn.tigris.org/) to connect to SVN repositories, and one of my favorite features is the icon overlay in Windows Explorer so you can see at a glance the files which are under source control and their state. However, I was only seeing a couple of the possible icons. What could be wrong?

After some investigation, it turns out that Windows enforces a hard limit on ...

If you are using conditional directives in your C# code, you know that you can't set a breakpoint on any code within the directives using Visual Studio. Thankfully, you can add a breakpoint programmatically:

#if  MYSYMBOL
#if DEBUG
System.Diagnostics.Debugger.Break();
#endif
DoSomethingForMySymbol();
#else
#if DEBUG
System.Diagnostics.Debugger.Break();
#endif
DoSomethingForEverythingElse();
#endif

System.Diagnostics.Debugger.Break() can only be called in Debug mode, so make sure you wrap it in a #if DEBUG check first. Good luck!

  


Here's a handy little tip for those of you using DataGrids or something similar, for instance, the Telerik RadGrid control. If you want to allow the user to double-click on a row to do something (edit the row, for example), implement the CellDoubleClick event handler for the grid and put your code in there.

If you do this, then double-clicks in the column header will also fire the event; this can happen if a user clicks the header too quickly while trying to sort. To prevent this, add code to check e.RowIndex. If the user double-clicked on a header, e.RowIndex ...
When programming for Windows, you'll sometimes want a container object (a form, a panel, etc.) to handle certain events, such as MouseOver, MouseMove, MouseUp, MouseDown, etc. But what happens if you have other controls in the container? You could write event handlers for each of those controls, but that seems like a lot of duplication of effort.

One solution to this problem is to send the child control's events that you'd like to capture to the event handlers of the container, e.g.
childControl.MouseMove += new MouseEventHandler(ParentControl_MouseMove);
This will send the event to the correct handler, but there is a ...
If you're like me, you sometimes use AJAX controls in your web page. And, if you're like me, you find that when they fail to behave as expected, you as the user are not notified as to the reason. Instead, the page will just stare back at you blankly: no spinning globe, no twirling fox to indicate that it is processing your request. Of course, what's really happened is that your AJAX request caused an unhandled exception on the server and the request was canceled. If you're like me (and if you've read this far I am forced to conclude ...